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:
| Name | Type | Required | Description |
|---|---|---|---|
task | BackgroundTaskDescriptor | Yes |
Returns: Promise<T>
reportProgress
reportProgress(taskHandle: string, update: TaskProgressUpdate): Promise<void>
Report progress for a running task. Called from inside the work handler.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
taskHandle | string | Yes | |
update | TaskProgressUpdate | Yes |
Returns: Promise<void>
isCancellationRequested
isCancellationRequested(taskHandle: string): Promise<boolean>
True if the user has requested cancellation. The work handler should return early.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
taskHandle | string | Yes |
Returns: Promise<boolean>
cancel
cancel(taskId: string): Promise<void>
Cancel a running task by ID.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
taskId | string | Yes |
Returns: Promise<void>
list
list(): Promise<BackgroundTaskInfo[]>
List tasks owned by this extension.
Returns: Promise<BackgroundTaskInfo[]>