Class: Zero::Moo::Subscriber

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

#address

Attributes inherited from Communicator

#context

Instance Method Summary collapse

Methods inherited from Publisher

#initialize, #push!

Methods inherited from Communicator

#initialize

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.

Yields:

  • (message)

Yield Parameters:

  • message (String)


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