Skip to main content

Function: withProgress()

withProgress<R>(options, task): Promise<R>

Show progress in Podman Desktop. Progress is shown while running the given callback and while the promise it returned isn't resolved nor rejected. The location at which progress should show (and other details) is defined via the passed ProgressOptions.

Type Parameters

R

Parameters

options: ProgressOptions

the options for the task's details

task

A callback returning a promise. Progress state can be reported with the provided Progress-object.

To report discrete progress, use increment to indicate how much work has been completed. Each call with a increment value will be summed up and reflected as overall progress until 100% is reached (a value of e.g. 10 accounts for 10% of work done). Note that currently only ProgressLocation.Notification is capable of showing discrete progress.

To monitor if the operation has been cancelled by the user, use the provided CancellationToken. Note that currently only ProgressLocation.Notification is supporting to show a cancel button to cancel the long-running operation.

Returns

Promise<R>

The promise the task-callback returned.

Examples

Here is a simple example

await window.withProgress({ location: ProgressLocation.TASK_WIDGET, title: `Running task` },
async progress => {
progress.report({message: 'task1' });
await task1();
progress.report({increment: 50, message: 'task2' });
await task2();
},
);

The error is propagated if thrown inside the task callback.

try {
await window.withProgress(
{ location: ProgressLocation.TASK_WIDGET, title: `Running task` },
async progress => {
throw new Error('error when running a task');
},
);
} catch (error) {
// do something with the error
}

You can return a value from the task callback

const result: number = await window.withProgress<number>(
{ location: ProgressLocation.TASK_WIDGET, title: `Running task` },
async progress => {
// compute something
return 55;
},
);

Defined in

packages/extension-api/src/extension-api.d.ts:2200