Module jls.util.Channel

Provide the Channel class.

Class Channel

Channel:new () Creates a new Channel.
channel:close (callback) Closes this channel.
channel:onClose () Returns a promise that resolves once the channel is closed.
channel:getName () Returns the name of this channel.
channel:bind ([closeWithAccepted[, scheme]]) Binds this channel.
channel:onAccept (ch) Accepts a new channel.
channel:connect (name) Connects this channel to the specified name.
channel:receiveStart (handleMessage) Starts receiving messages on this channel.
channel:receiveStop () Stops receiving messages on this channel.
channel:writeMessage (payload[, messageType[, callback]]) Writes a message on this channel.


Class Channel

The Channel class. Provides a local message passing interface suitable for process and thread event based message passing. The messages are sent and received as string on a channel. The goal is to abstract the message transport implementation, that can internally be a queue, a pipe or a socket. The channel resource is represented by an opaque string and can be generated automatically. Internally using URI with authentication keys, pipe://pub.priv@local/p12345 or tcp://pub.priv@localhost:12345. This interface is used for worker that abstract the thread.
Channel:new ()
Creates a new Channel. A channel can be a server using the bind method or a client using the connect method but not both.
channel:close (callback)
Closes this channel.

Parameters:

  • callback function an optional callback function to use in place of promise.

Returns:

    jls.lang.Promise a promise that resolves once the channel is closed.
channel:onClose ()
Returns a promise that resolves once the channel is closed.

Returns:

    jls.lang.Promise a promise that resolves once the channel is closed.
channel:getName ()
Returns the name of this channel.

Returns:

    string the name of this channel.
channel:bind ([closeWithAccepted[, scheme]])
Binds this channel. When bound, the channel name can be used for connection.

Parameters:

  • closeWithAccepted boolean true to indicate this channel shall be closed after all the accepted channels are closed. (optional)
  • scheme string the scheme to use. (optional)

Returns:

    jls.lang.Promise a promise that resolves once the server channel is bound.
channel:onAccept (ch)
Accepts a new channel. This method should be overriden, the default implementation closes the channel.

Parameters:

  • ch the channel to accept.
channel:connect (name)
Connects this channel to the specified name.

Parameters:

  • name string the name of the channel.

Returns:

    jls.lang.Promise a promise that resolves once the channel is connected.
channel:receiveStart (handleMessage)
Starts receiving messages on this channel. The handler will be called with the payload and the message type.

Parameters:

  • handleMessage function a function that will be called when a message is received.
channel:receiveStop ()
Stops receiving messages on this channel. This server channel shall not be used anymore.
channel:writeMessage (payload[, messageType[, callback]])
Writes a message on this channel.

Parameters:

  • payload string the message to send
  • messageType number the message type, default is Channel.MESSAGETYPEUSER. (optional)
  • callback function an optional callback function to use in place of promise. (optional)

Returns:

    jls.lang.Promise a promise that resolves once the message has been sent.
generated by LDoc 1.4.6 Last updated 2021-12-02 21:21:01