Module: OMQ::Writable

Includes:
QueueWritable
Included in:
DEALER, PAIR, PUB, PUSH, REP, REQ, ROUTER, XPUB, XSUB
Defined in:
lib/omq/writable.rb

Overview

Pure Ruby Writable mixin. Enqueues messages to the engine’s send path.

Constant Summary collapse

EMPTY_PART =
"".b.freeze

Instance Method Summary collapse

Methods included from QueueWritable

#enqueue

Instance Method Details

#<<(message) ⇒ self

Sends a message (chainable).

Parameters:

  • message (String, Array<String>)

Returns:

  • (self)


37
38
39
# File 'lib/omq/writable.rb', line 37

def <<(message)
  send(message)
end

#send(message) ⇒ self

Sends a message.

Parameters:

  • message (String, Array<String>)

    message parts

Returns:

  • (self)

Raises:

  • (IO::TimeoutError)

    if write_timeout exceeded



21
22
23
24
25
26
27
28
29
# File 'lib/omq/writable.rb', line 21

def send(message)
  parts = freeze_message(message)

  Reactor.run timeout: @options.write_timeout do |task|
    @engine.enqueue_send(parts)
  end

  self
end

#wait_writable(timeout = @options.write_timeout) ⇒ true

Waits until the socket is writable.

Parameters:

  • timeout (Numeric, nil) (defaults to: @options.write_timeout)

    timeout in seconds

Returns:

  • (true)


47
48
49
# File 'lib/omq/writable.rb', line 47

def wait_writable(timeout = @options.write_timeout)
  true
end