vlocode-project - v1.40.0-beta-4
    Preparing search index...

    Class Task<TResult, TProgress>

    Represents a Promise that supports progress reporting and cancellation.

    ProgressablePromise extends the standard Promise pattern by allowing consumers to:

    • Subscribe to progress updates via an event emitter.
    • Cancel the underlying asynchronous operation using a cancellation token.
    • Chain with then, catch, and finally methods, returning a new ProgressablePromise.
    const progressable = new ProgressablePromise<number>((progress, token) => {
    return new Promise<number>((resolve, reject) => {
    let count = 0;
    const interval = setInterval(() => {
    if (token?.isCancellationRequested) {
    clearInterval(interval);
    reject(new Error('Cancelled'));
    return;
    }
    progress?.(++count);
    if (count === 10) {
    clearInterval(interval);
    resolve(count);
    }
    }, 100);
    });
    });

    progressable.on('progress', (value) => console.log('Progress:', value));

    Type Parameters

    • TResult

      The type of the resolved value of the promise.

    • TProgress = unknown

      The type of the progress update values (defaults to TResult).

    Implements

    Index

    Constructors

    Properties

    "[toStringTag]": "Task<T>" = 'Task<T>'
    cancellationTokenSource: CancellationTokenSource = ...
    events: EventEmitter<DefaultEventMap> = ...
    taskPromise: Promise<any>
    taskStatus: TaskStatus = TaskStatus.executing

    Accessors

    Methods

    • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

      Parameters

      • Optionalonfinally: null | (() => void)

        The callback to execute when the Promise is settled (fulfilled or rejected).

      Returns this

      A Promise for the completion of the callback.