Class MatrixScheduler<T>

Type Parameters

Constructors

  • Construct a scheduler for Matrix. Requires MatrixScheduler#setProcessFunction to be provided with a way of processing events.

    Type Parameters

    Parameters

    • retryAlgorithm: ((event, attempts, err) => number) = MatrixScheduler.RETRY_BACKOFF_RATELIMIT

      Optional. The retry algorithm to apply when determining when to try to send an event again. Defaults to MatrixScheduler.RETRY_BACKOFF_RATELIMIT.

        • (event, attempts, err): number
        • Default retry algorithm for the matrix scheduler. Retries events up to 4 times with exponential backoff.

          Parameters

          • event: null | MatrixEvent
          • attempts: number

            Number of attempts that have been made, including the one that just failed (ie. starting at 1)

          • err: MatrixError

          Returns number

          See

          retryAlgorithm

    • queueAlgorithm: ((event) => null | string) = MatrixScheduler.QUEUE_MESSAGES

      Optional. The queuing algorithm to apply when determining which events should be sent before the given event. Defaults to MatrixScheduler.QUEUE_MESSAGES.

        • (event): null | string
        • Queues m.room.message events and lets other events continue concurrently.

          Parameters

          Returns null | string

          See

          queueAlgorithm

    Returns MatrixScheduler<T>

Properties

activeQueues: string[] = []
procFn: null | ProcessFunction<T> = null
queueAlgorithm: ((event) => null | string) = MatrixScheduler.QUEUE_MESSAGES

The queuing algorithm to apply to events. This function must be idempotent as it may be called multiple times with the same event. All queues created are serviced in a FIFO manner. To send the event ASAP, return null which will not put this event in a queue. Events that fail to send that form part of a queue will be removed from the queue and the next event in the queue will be sent.

Type declaration

    • (event): null | string
    • Parameters

      Returns null | string

Returns

The name of the queue to put the event into. If a queue with this name does not exist, it will be created. If this is null, the event is not put into a queue and will be sent concurrently.

queues: Record<string, IQueueEntry<T>[]> = {}
retryAlgorithm: ((event, attempts, err) => number) = MatrixScheduler.RETRY_BACKOFF_RATELIMIT

The retry algorithm to apply when retrying events. To stop retrying, return -1. If this event was part of a queue, it will be removed from the queue.

Type declaration

    • (event, attempts, err): number
    • Parameters

      • event: null | MatrixEvent

        The event being retried.

      • attempts: number

        The number of failed attempts. This will always be >= 1.

      • err: MatrixError

        The most recent error message received when trying to send this event.

      Returns number

Returns

The number of milliseconds to wait before trying again. If this is 0, the request will be immediately retried. If this is -1, the event will be marked as EventStatus.NOT_SENT and will not be retried.

Methods

  • Parameters

    • queueName: string
    • err: unknown

    Returns void

  • Retrieve a queue based on an event. The event provided does not need to be in the queue.

    Parameters

    Returns null | MatrixEvent[]

    A shallow copy of events in the queue or null. Modifying this array will not modify the list itself. Modifying events in this array will modify the underlying event in the queue.

    See

    MatrixScheduler.removeEventFromQueue To remove an event from the queue.

  • Queue an event if it is required and start processing queues.

    Parameters

    Returns null | Promise<T>

    A promise if the event was queued, which will be resolved or rejected in due time, else null.

  • Remove this event from the queue. The event is equal to another event if they have the same ID returned from event.getId().

    Parameters

    Returns boolean

    True if this event was removed.

  • Set the process function. Required for events in the queue to be processed. If set after events have been added to the queue, this will immediately start processing them.

    Parameters

    Returns void

  • Queues m.room.message events and lets other events continue concurrently.

    Parameters

    Returns null | string

    See

    queueAlgorithm

  • Default retry algorithm for the matrix scheduler. Retries events up to 4 times with exponential backoff.

    Parameters

    • event: null | MatrixEvent
    • attempts: number

      Number of attempts that have been made, including the one that just failed (ie. starting at 1)

    • err: MatrixError

    Returns number

    See

    retryAlgorithm

Generated using TypeDoc