Class Procedure<Input, Output>

A simple abstraction of a procedure (the P in RPC). Allows you to turn a function or callback into a procedure, which can be called via the transport specified.

See

TypedEmitter

Type Parameters

  • Input = undefined

    Type of input parameter the procedure accepts. Defaults to undefined.

  • Output = undefined

    Type of output value the procedure returns. Defaults to undefined.

Hierarchy

Implements

Constructors

  • Initializes a new Procedure.

    Type Parameters

    • Input = undefined

      Type of input parameter the procedure accepts. Defaults to undefined.

    • Output = undefined

      Type of output value the procedure returns. Defaults to undefined.

    Parameters

    • callback: ((input: Input) => Output)

      The underlying callback function powering the procedure itself. The callback may be asynchronous.

        • (input: Input): Output
        • Parameters

          • input: Input

          Returns Output

    • Optional options: Partial<ProcedureDefinitionOptions> = {}

      Options for a Procedure. Defaults to {}.

    Returns Procedure<Input, Output>

Properties

#endpoint?: string
#uuid?: string
callback: ((input: Input) => Output)

Type declaration

    • (input: Input): Output
    • The underlying callback function powering the procedure itself. The callback may be asynchronous.

      Parameters

      • input: Input

      Returns Output

The options in use by the Procedure, including defaults.

sockets: Socket[] = []

The underlying nanomsg sockets used for data transmission.

Accessors

  • get endpoint(): undefined | string
  • The endpoint at which the Procedure, when bound, can be called.

    Returns undefined | string

  • set endpoint(value: undefined | string): void
  • Parameters

    • value: undefined | string

    Returns void

  • get uuid(): undefined | string
  • A v5 uuid generated from endpoint, used to identify ping requests.

    Returns undefined | string

  • set uuid(value: undefined | string): void
  • Parameters

    • value: undefined | string

    Returns void

Methods

  • Emits and optionally logs given input data.

    Parameters

    • data: Input

      The input data to emit and log.

    Returns void

  • Emits and optionally logs a given error.

    Parameters

    • message: string

      A custom error message describing the cause of the error. The message will be concatenated with the Procedure's endpoint.

    • Optional error: ProcedureError

      The error.

    Returns void

  • Emits and optionally logs the unbind event.

    See

    unbind

    Returns void

  • Asynchrously handles the socket's data event, representing requests to call the Procedure.

    Parameters

    • data: Buffer

      The encoded input Buffer.

    • socket: Socket

      The socket the data was received on.

    Returns Promise<void>

  • Handles the error event for the underlying sockets of the Procedure.

    Parameters

    • error: unknown

      The error data passed by the socket.

    Returns void

  • Attempts to decode the given Buffer.

    Returns

    If successful, an object of shape { input: Input | Ping }, otherwise { error: unknown }.

    Parameters

    • buffer: Buffer

      The Buffer to decode.

    Returns {
        error?: undefined;
        input: Input | Ping;
    } | {
        error: ProcedureInternalServerError;
        input?: undefined;
    }

  • Attempts to encode the given response for transmission back to the Procedure's caller.

    Returns

    A Buffer containing the encoded response.

    Parameters

    • response: Response<Output>

      The response to encode.

    Returns Buffer

  • Handles ping requests for a given socket.

    Returns

    true when the decoded data object was a valid Ping and handled, otherwise false.

    Parameters

    • data: unknown

      The decoded incoming data object.

    • socket: Socket

      The socket the data was received on.

    Returns data is Ping

  • Attempts to send the encoded buffer back to the Procedure's caller.

    Returns

    true when the encoded Buffer was successfully sent, otherwise false.

    Parameters

    • buffer: Buffer

      A Buffer containing the encoded response.

    • socket: Socket

      The socket through which to send the response.

    Returns boolean

  • Type Parameters

    Parameters

    Returns Procedure<Input, Output>

  • Binds the Procedure to an endpoint, making it available to be called.

    Returns

    The bound Procedure for method chaining.

    See

    unbind

    Parameters

    • endpoint: string

      The endpoint at which the procedure will be callable.

    • Optional ipv6: boolean = false

      Whether the endpoint requires ipv6 support. Defaults to false.

    Returns Procedure<Input, Output>

  • Type Parameters

    Parameters

    Returns boolean

  • Returns (string | symbol)[]

  • Returns number

  • Type Parameters

    Parameters

    • event: E

    Returns number

  • Type Parameters

    Parameters

    • event: E

    Returns ProcedureEvents<Input>[E][]

  • Type Parameters

    Parameters

    Returns Procedure<Input, Output>

  • Type Parameters

    Parameters

    Returns Procedure<Input, Output>

  • Type Parameters

    Parameters

    Returns Procedure<Input, Output>

  • Type Parameters

    Parameters

    Returns Procedure<Input, Output>

  • Type Parameters

    Parameters

    Returns Procedure<Input, Output>

  • Type Parameters

    Parameters

    • event: E

    Returns ProcedureEvents<Input>[E][]

  • Type Parameters

    Parameters

    • Optional event: E

    Returns Procedure<Input, Output>

  • Type Parameters

    Parameters

    Returns Procedure<Input, Output>

  • Parameters

    • maxListeners: number

    Returns Procedure<Input, Output>

Generated using TypeDoc