Instance able to reschedule the ordering of promises for a given app

Remarks

Since 1.20.0

Type Parameters

  • TMetaData = unknown

Hierarchy

  • Scheduler

Properties

report: (() => SchedulerReportItem<TMetaData>[])

Type declaration

    • (): SchedulerReportItem<TMetaData>[]
    • Produce an array containing all the scheduled tasks so far with their execution status. If the task has been executed, it includes a string representation of the associated output or error produced by the task if any.

      Tasks will be returned in the order they get executed by the scheduler.

      Remarks

      Since 1.25.0

      Returns SchedulerReportItem<TMetaData>[]

schedule: (<T>(task: Promise<T>, label?: string, metadata?: TMetaData) => Promise<T>)

Type declaration

    • <T>(task: Promise<T>, label?: string, metadata?: TMetaData): Promise<T>
    • Wrap a new task using the Scheduler

      Remarks

      Since 1.20.0

      Type Parameters

      • T

      Parameters

      • task: Promise<T>
      • Optional label: string
      • Optional metadata: TMetaData

      Returns Promise<T>

scheduleFunction: (<TArgs, T>(asyncFunction: ((...args: TArgs) => Promise<T>)) => ((...args: TArgs) => Promise<T>))

Type declaration

    • <TArgs, T>(asyncFunction: ((...args: TArgs) => Promise<T>)): ((...args: TArgs) => Promise<T>)
    • Automatically wrap function output using the Scheduler

      Remarks

      Since 1.20.0

      Type Parameters

      • TArgs extends any[]

      • T

      Parameters

      • asyncFunction: ((...args: TArgs) => Promise<T>)
          • (...args: TArgs): Promise<T>
          • Parameters

            • Rest ...args: TArgs

            Returns Promise<T>

      Returns ((...args: TArgs) => Promise<T>)

        • (...args: TArgs): Promise<T>
        • Parameters

          • Rest ...args: TArgs

          Returns Promise<T>

waitAll: (() => Promise<void>)

Type declaration

    • (): Promise<void>
    • Wait all scheduled tasks, including the ones that might be created by one of the resolved task

      Remarks

      Since 1.20.0

      Returns Promise<void>

waitFor: (<T>(unscheduledTask: Promise<T>) => Promise<T>)

Type declaration

    • <T>(unscheduledTask: Promise<T>): Promise<T>
    • Wait as many scheduled tasks as need to resolve the received Promise

      Some tests frameworks like supertest are not triggering calls to subsequent queries in a synchronous way, some are waiting an explicit call to then to trigger them (either synchronously or asynchronously)... As a consequence, none of waitOne or waitAll cannot wait for them out-of-the-box.

      This helper is responsible to wait as many scheduled tasks as needed (but the bare minimal) to get unscheduledTask resolved. Once resolved it returns its output either success or failure.

      Be aware that while this helper will wait eveything to be ready for unscheduledTask to resolve, having uncontrolled tasks triggering stuff required for unscheduledTask might be a source a uncontrollable and not reproducible randomness as those triggers cannot be handled and scheduled by fast-check.

      Remarks

      Since 2.24.0

      Type Parameters

      • T

      Parameters

      • unscheduledTask: Promise<T>

      Returns Promise<T>

waitOne: (() => Promise<void>)

Type declaration

    • (): Promise<void>
    • Wait one scheduled task to be executed

      Throws

      Whenever there is no task scheduled

      Remarks

      Since 1.20.0

      Returns Promise<void>

Methods

  • Schedule a sequence of Promise to be executed sequencially. Items within the sequence might be interleaved by other scheduled operations.

    Please note that whenever an item from the sequence has started, the scheduler will wait until its end before moving to another scheduled task.

    A handle is returned by the function in order to monitor the state of the sequence. Sequence will be marked:

    • done if all the promises have been executed properly
    • faulty if one of the promises within the sequence throws

    Remarks

    Since 1.20.0

    Parameters

    Returns {
        done: boolean;
        faulty: boolean;
        task: Promise<{
            done: boolean;
            faulty: boolean;
        }>;
    }

    • done: boolean
    • faulty: boolean
    • task: Promise<{
          done: boolean;
          faulty: boolean;
      }>

Generated using TypeDoc