Class: Shamu::Events::InMemory::AsyncService
- Inherits:
-
Service
- Object
- Services::Service
- EventsService
- Service
- Shamu::Events::InMemory::AsyncService
- Defined in:
- lib/shamu/events/in_memory/async_service.rb
Overview
An asynchronous version of Service. Event subscribers should be able to handle events coming in on a separate thread.
Instance Method Summary collapse
-
#dispatch
Dispatch all pending mssages in the given named channels.
-
#initialize ⇒ AsyncService
constructor
A new instance of AsyncService.
Methods inherited from Service
#channel_stats, #publish, #subscribe
Methods included from ChannelStats
Methods inherited from EventsService
bridge, create, #deserialize, #publish, #serialize, #subscribe
Methods inherited from Services::Service
#cache_for, #cached_lookup, #entity_list, #entity_lookup_list, #find_by_lookup, #lazy_association, #lookup_association
Constructor Details
#initialize ⇒ AsyncService
Returns a new instance of AsyncService.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/shamu/events/in_memory/async_service.rb', line 12 def initialize ObjectSpace.define_finalizer self do threads = mutex.synchronize do channels.map do |_, state| state[:queue].close state[:thread] end end ThreadsWait.all_waits( *threads ) end super end |
Instance Method Details
#dispatch
This method returns an undefined value.
Dispatch all pending mssages in the given named channels.
28 29 30 |
# File 'lib/shamu/events/in_memory/async_service.rb', line 28 def dispatch # No-op since messages are immediately dispatched on background threads. end |