Class: EZMQ::Server

Inherits:
Socket show all
Defined in:
lib/ezmq.rb

Overview

Reply socket that listens for and replies to requests.

Instance Attribute Summary (collapse)

Attributes inherited from Socket

#context, #decode, #encode, #socket

Instance Method Summary (collapse)

Methods inherited from Socket

#bind, #connect, #receive, #send

Constructor Details

- (Server) initialize(provides: -> m { m }, **options)

Creates a new Server socket.

Parameters:

  • provides (lambda)

    the service provided by this server.

  • options (Hash)

    optional parameters

See Also:



98
99
100
101
# File 'lib/ezmq.rb', line 98

def initialize(provides: -> m { m }, **options)
  @provides = provides
  super :bind, ZMQ::REP, options
end

Instance Attribute Details

- (Object) provides

Returns the value of attribute provides



87
88
89
# File 'lib/ezmq.rb', line 87

def provides
  @provides
end

Instance Method Details

- (void) listen(handler: -> { send @provides.call(receive) })

This method returns an undefined value.

By default, waits to receive a message, calls @action with it, replies with the result, then loops.

Parameters:

  • handler (lambda)

    how requests are handled.



110
111
112
# File 'lib/ezmq.rb', line 110

def listen(handler: -> { send @provides.call(receive) })
  loop { handler.call }
end