class Shamu::Events::InMemory::AsyncService
An asynchronous version of {Service}. Event subscribers should be able to handle events coming in on a separate thread.
Public Class Methods
new()
click to toggle source
Calls superclass method
Shamu::Events::InMemory::Service::new
# 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
Public Instance Methods
dispatch()
click to toggle source
(see Service#dispatch
)
# File lib/shamu/events/in_memory/async_service.rb, line 28 def dispatch # No-op since messages are immediately dispatched on background threads. end
Private Instance Methods
channel_thread( state )
click to toggle source
# File lib/shamu/events/in_memory/async_service.rb, line 41 def channel_thread( state ) Thread.new do dispatch_channel( state ) end end
create_channel( _ )
click to toggle source
Calls superclass method
Shamu::Events::InMemory::Service#create_channel
# File lib/shamu/events/in_memory/async_service.rb, line 34 def create_channel( _ ) state = super state[:thread] = channel_thread( state ) state[:queue] = Queue.new state end