Sha256: 6d6daad87c8ccb0de948fe6273cce0faf8c6f5f3a878b99d66878491c41d7def
Contents?: true
Size: 1.08 KB
Versions: 16
Compression:
Stored size: 1.08 KB
Contents
require "thread" require "thwait" module Shamu module Events module InMemory # An asynchronous version of {Service}. Event subscribers should be able # to handle events coming in on a separate thread. class AsyncService < InMemory::Service initialize do 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 end # (see Service#dispatch) def dispatch # No-op since messages are immediately dispatched on background threads. end private def create_channel( _ ) state = super state[:thread] = channel_thread( state ) state[:queue] = Queue.new state end def channel_thread( state ) Thread.new do dispatch_channel( state ) end end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems