Class: Zero::Moo::Subscriber
- Inherits:
-
Publisher
- Object
- Communicator
- Publisher
- Zero::Moo::Subscriber
- Defined in:
- lib/zero/moo/subscriber.rb
Defined Under Namespace
Classes: ConnectError, Error, InvalidAddressError, MessageError, MissingAddressError, SocketOptionError, SocketShutdownError
Instance Attribute Summary
Attributes inherited from Publisher
Attributes inherited from Communicator
Instance Method Summary collapse
-
#on_receive {|message| ... } ⇒ void
Add callbacks.
Methods inherited from Publisher
Methods inherited from Communicator
Constructor Details
This class inherits a constructor from Zero::Moo::Publisher
Instance Method Details
#on_receive {|message| ... } ⇒ void
This method returns an undefined value.
Add callbacks. The block will called with one argument. The message.
32 33 34 35 36 37 38 39 |
# File 'lib/zero/moo/subscriber.rb', line 32 def on_receive &block listen! unless thread.instance_of? Thread unless @receivers ObjectSpace.define_finalizer(WeakRef.new(self), proc{ stop! }) end @receivers ||= [] @receivers << block end |