Represents an async task.

interface Task<Args extends any[] = [], Result = void> {
    cancel(): void;
    delay(delay: number, ...args: Args): CancelablePromise<Result>;
    delayIfNotQueued(delay: number, ...args: Args): CancelablePromise<Result>;
    isRunning(): boolean;
    run(...args: Args): CancelablePromise<Result>;
}

Type Parameters

  • Args extends any[] = []
  • Result = void

Methods

  • Cancels the current execution.

    Returns void

  • Runs the task delayed. Cancels the last execution.

    Parameters

    • delay: number

      milliseconds to wait until task execution

    • ...args: Args

      the arguments given to the task function.

    Returns CancelablePromise<Result>

    the promise.

  • Runs the task delayed. But only if it is not waiting for execution or executing. Does not cancel the last execution.

    Parameters

    • delay: number

      milliseconds to wait until next task execution.

    • ...args: Args

      the arguments given to the task function. If queued again.

    Returns CancelablePromise<Result>

    the promise.

  • Returns the current running state.

    Returns boolean