Skip to main content

api.tasks

Interface: ITasksApi

Implementation tier: T2

Run long-running background tasks with progress reporting, cancellation support, and status bar integration.

Permissions

  • tasks

Methods

run

run<T = void>(task: BackgroundTaskDescriptor): Promise<T>

Run a long-running task. The host invokes workEndpoint via reverse-RPC with a taskHandle the worker uses to report progress and check for cancellation. The host shows a progress entry in the status bar and a notification on completion if notifyOnComplete is set.

Parameters:

NameTypeRequiredDescription
taskBackgroundTaskDescriptorYes

Returns: Promise<T>


reportProgress

reportProgress(taskHandle: string, update: TaskProgressUpdate): Promise<void>

Report progress for a running task. Called from inside the work handler.

Parameters:

NameTypeRequiredDescription
taskHandlestringYes
updateTaskProgressUpdateYes

Returns: Promise<void>


isCancellationRequested

isCancellationRequested(taskHandle: string): Promise<boolean>

True if the user has requested cancellation. The work handler should return early.

Parameters:

NameTypeRequiredDescription
taskHandlestringYes

Returns: Promise<boolean>


cancel

cancel(taskId: string): Promise<void>

Cancel a running task by ID.

Parameters:

NameTypeRequiredDescription
taskIdstringYes

Returns: Promise<void>


list

list(): Promise<BackgroundTaskInfo[]>

List tasks owned by this extension.

Returns: Promise<BackgroundTaskInfo[]>