Interface WorkspaceLock

Utility service to execute mutually exclusive actions.

interface WorkspaceLock {
    cancelWrite(): void;
    read<T>(action: (() => MaybePromise<T>)): Promise<T>;
    write(action: ((token: CancellationToken) => MaybePromise<void>)): Promise<void>;
}

Implemented by

Methods

  • Performs a single action, like computing completion results or providing workspace symbols. Read actions will only be executed after all write actions have finished. They will be executed in parallel if possible.

    If a write action is currently running, the read action will be queued up and executed afterwards. If a new write action is queued up while a read action is waiting, the write action will receive priority and will be handled before the read action.

    Note that read actions are not allowed to modify anything in the workspace. Please use write instead.

    Type Parameters

    • T

    Parameters

    Returns Promise<T>

  • Performs a single async action, like initializing the workspace or processing document changes. Only one action will be executed at a time.

    When another action is queued up, the token provided for the action will be cancelled. Assuming the action makes use of this token, the next action only has to wait for the current action to finish cancellation.

    Parameters

    Returns Promise<void>