Class EventPoll<TReturnType>

Poll in an event based way. This Poll is Asynchronous. It exploits:

  • The EventEmitter to emit events
  • The setInterval function to poll
It can be used to trigger events every time
- When balance is updated after a transaction is sent a message is sent
- When a transaction is mined a message is sent
- When a certain block is mined an operation can start
...

Type Parameters

  • TReturnType

Hierarchy

  • EventEmitter
    • EventPoll

Constructors

  • Constructor for creating an instance of EventPoll.

    Type Parameters

    • TReturnType

    Parameters

    • pollingFunction: (() => Promise<TReturnType>)

      The function to be executed repeatedly.

    • requestIntervalInMilliseconds: number

      The interval in milliseconds between each execution of the polling function.

    • OptionalhasToStopOnError: boolean

      Indicates whether to stop polling if an error occurs.

    Returns EventPoll<TReturnType>

Accessors

  • get getCurrentIteration(): number
  • Get how many iterations have been done.

    Returns number

    The number of iterations.

Methods

  • Listen to the 'data' event. This method is the redefinition of the EventEmitter.on method. Because the EventEmitter.on method does not allow to specify the type of the data. And we must be type safe.

    This is equivalent to:

    eventPoll.on('data', (data) => { ... });
    

    Parameters

    Returns this

  • Listen to the 'error' event. This method is the redefinition of the EventEmitter.on method. Because the EventEmitter.on method does not allow to specify the type of the data. And we must be type safe.

    This is equivalent to:

    eventPoll.on('error', (data) => { ... });
    

    Parameters

    • onErrorCallback: ((error: Error) => void)

      The callback to be called when the event is emitted.

        • (error): void
        • Parameters

          • error: Error

          Returns void

    Returns this

  • Listen to the 'start' event. This happens when the poll is stopped.

    Parameters

    Returns this

  • Listen to the 'stop' event. This happens when the poll is stopped.

    Parameters

    Returns this