event_buffer.rb 619 B

123456789101112131415161718192021222324252627
  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