Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RequestReplyHelper<Result>

Helper for managing requests and replies that are identified via a number.

const helper = new RequestReplyHelper({
timeout: 30000
});

// Generate an id and get a promise for the request and pass the id somewhere
const [ id, promise ] = helper.prepareRequest();

// Later on register a reply
helper.registerReply(id, replyDataHere);

// Or an error if something goes wrong
helper.registerError(id, new Error('Things went wrong'));

Type parameters

  • Result

Hierarchy

  • RequestReplyHelper

Index

Constructors

constructor

Methods

prepareRequest

  • Prepare a request, will return the identifier to use and a promise that will resolve when the reply is registered.

    Parameters

    Returns [id: number, result: Promise<Result>]

    array with request id and promise. The promise will resolve or reject when a result or error is registered, or when it times out

registerError

  • registerError(id: number, error?: Error): void
  • Register that an error occurred for the given identifier. This will reject the promise associated with the identifier.

    Parameters

    • id: number
      • identifier as given previously by prepareRequest
    • Optional error: Error
      • optional error to reject with

    Returns void

registerReply

  • registerReply(id: number, result: Result): void
  • Register that a reply has been received for the given identifier. This will resolve the promise associated with the identifier.

    Parameters

    • id: number
      • identifier as given previously by prepareRequest
    • result: Result
      • the result to resolve with

    Returns void

Generated using TypeDoc