Class: IronAdmin::Live::PollCache
- Inherits:
-
Object
- Object
- IronAdmin::Live::PollCache
- Defined in:
- lib/iron_admin/live/poll_cache.rb
Instance Method Summary collapse
- #clear! ⇒ Object
- #fetch(stream) ⇒ Object
-
#initialize ⇒ PollCache
constructor
A new instance of PollCache.
- #push(stream, payload) ⇒ Object
Constructor Details
#initialize ⇒ PollCache
Returns a new instance of PollCache.
6 7 8 9 |
# File 'lib/iron_admin/live/poll_cache.rb', line 6 def initialize @mutex = Mutex.new @streams = Hash.new { |hash, key| hash[key] = [] } end |
Instance Method Details
#clear! ⇒ Object
23 24 25 |
# File 'lib/iron_admin/live/poll_cache.rb', line 23 def clear! @mutex.synchronize { @streams.clear } end |
#fetch(stream) ⇒ Object
17 18 19 20 21 |
# File 'lib/iron_admin/live/poll_cache.rb', line 17 def fetch(stream) @mutex.synchronize do @streams.delete(stream.to_s) || [] end end |
#push(stream, payload) ⇒ Object
11 12 13 14 15 |
# File 'lib/iron_admin/live/poll_cache.rb', line 11 def push(stream, payload) @mutex.synchronize do @streams[stream.to_s] << payload.to_s end end |