Class: Shamu::Events::InMemory::AsyncService

Inherits:
Service show all
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

Methods inherited from Service

#channel_stats, #publish, #subscribe

Methods included from ChannelStats

#channel_stats

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

#initializeAsyncService

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.

Parameters:

  • names (Array<String>)

    of the channels to dispatch. Dispatches to all queues if empty.



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