Method: Mongo::Server::ConnectionBase#dispatch

Defined in:
lib/mongo/server/connection_base.rb

#dispatch(messages, context, options = {}) ⇒ Protocol::Message | nil

Note:

This method is named dispatch since ‘send’ is a core Ruby method on all objects.

Note:

For backwards compatibility, this method accepts the messages as an array. However, exactly one message must be given per invocation.

Dispatch a single message to the connection. If the message requires a response, a reply will be returned.

Examples:

Dispatch the message.

connection.dispatch([ insert ])

Options Hash (options):

  • :deserialize_as_bson (Boolean)

    Whether to deserialize the response to this message using BSON objects in place of native Ruby types wherever possible.

Raises:

  • When there is a network error.

Since:

  • 2.0.0

Parameters:

  • A one-element array containing the message to dispatch.

  • The operation context.

  • (defaults to: {})

Returns:

  • The reply if needed.

API:

  • semipublic



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/mongo/server/connection_base.rb', line 150

def dispatch(messages, context, options = {})
  # The monitoring code does not correctly handle multiple messages,
  # and the driver internally does not send more than one message at
  # a time ever. Thus prohibit multiple message use for now.
  if messages.length != 1
    raise ArgumentError, 'Can only dispatch one message at a time'
  end
  if description.unknown?
    raise Error::InternalDriverError, "Cannot dispatch a message on a connection with unknown description: #{description.inspect}"
  end
  message = messages.first
  deliver(message, context, options)
end