trabajo-afectivo/lib/event_buffer.rb

28 lines
619 B
Ruby
Raw Normal View History

2013-06-19 12:04:09 +00:00
module EventBuffer
2016-04-13 23:50:22 +00:00
def self.list(key)
if !Thread.current[:event_buffer]
Thread.current[:event_buffer] = {}
end
Thread.current[:event_buffer][key] || []
2013-06-19 12:04:09 +00:00
end
2016-04-13 23:50:22 +00:00
def self.add(key, item)
2013-06-19 12:04:09 +00:00
if !Thread.current[:event_buffer]
2016-04-13 23:50:22 +00:00
Thread.current[:event_buffer] = {}
end
if !Thread.current[:event_buffer][key]
Thread.current[:event_buffer][key] = []
2013-06-19 12:04:09 +00:00
end
2016-04-13 23:50:22 +00:00
Thread.current[:event_buffer][key].push item
2013-06-19 12:04:09 +00:00
end
2016-04-13 23:50:22 +00:00
def self.reset(key)
return if !Thread.current[:event_buffer]
return if !Thread.current[:event_buffer][key]
2016-04-13 23:50:22 +00:00
Thread.current[:event_buffer][key] = []
2013-06-19 12:04:09 +00:00
end
end