event_buffer.rb 618 B

1234567891011121314151617181920212223242526
  1. module EventBuffer
  2. def self.list(key)
  3. if !Thread.current[:event_buffer]
  4. Thread.current[:event_buffer] = {}
  5. end
  6. Thread.current[:event_buffer][key] || []
  7. end
  8. def self.add(key, item)
  9. if !Thread.current[:event_buffer]
  10. Thread.current[:event_buffer] = {}
  11. end
  12. if !Thread.current[:event_buffer][key]
  13. Thread.current[:event_buffer][key] = []
  14. end
  15. Thread.current[:event_buffer][key].push item
  16. end
  17. def self.reset(key)
  18. return if !Thread.current[:event_buffer]
  19. return if !Thread.current[:event_buffer][key]
  20. Thread.current[:event_buffer][key] = []
  21. end
  22. end