Class: OMQ::Rust::Monitor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/omq/rs/socket.rb

Overview

Enumerable stream of socket lifecycle events.

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Monitor

Creates a monitor for a socket.

Normally obtained through Socket#monitor.

Parameters:



180
181
182
# File 'lib/omq/rs/socket.rb', line 180

def initialize(socket)
  @socket = socket
end

Instance Method Details

#each {|event| ... } ⇒ Enumerator?

Yields monitor events until socket closes.

Yield Parameters:

  • event (Hash)

Returns:

  • (Enumerator, nil)

    enumerator without a block



204
205
206
207
208
209
210
211
212
# File 'lib/omq/rs/socket.rb', line 204

def each
  return enum_for(__method__) unless block_given?

  while (event = recv)
    yield event
  end
rescue IOError
  raise unless @socket.closed?
end

#recv(timeout: nil) ⇒ Hash?

Receives next monitor event.

Parameters:

  • timeout (Numeric, nil) (defaults to: nil)

    maximum wait in seconds

Returns:

  • (Hash, nil)

    event fields, or nil when socket closes

Raises:

  • (IO::TimeoutError)

    if timeout expires



189
190
191
# File 'lib/omq/rs/socket.rb', line 189

def recv(timeout: nil)
  @socket.monitor_event(timeout: timeout)
end

#recv_nowaitHash?

Receives next available monitor event without blocking.

Returns:

  • (Hash, nil)


196
197
198
# File 'lib/omq/rs/socket.rb', line 196

def recv_nowait
  @socket.try_monitor_event
end