I am playing around with MessageService#showProgress
, I understand how to report progress and cancel it but I can’t figure out what to call to notify the MessageService
that the progress is complete.
This is the code I used to test it:
const progress = await this.messageService.showProgress({
text: "Counting",
actions: ["Action 1", "Action 2"]
});
for (let n = 1; n <= 10; n++) {
setTimeout(() => {
progress.report({
message: `${n}/10`,
work: { done: n, total: 10 }
});
}, 1000 * n);
}
const result = await progress.result;
alert(result);
[original thread by Hanksha]
[Alex Tugarev]
Hi @hanksha! Calling progress.cancel()
is indeed what you looking for. The result might have the value of the ProgressMessage.Cancel
const, or one the provided actions.
[Hanksha]
Isn’t calling cancel
to complete the progress a bit weird? How would you differentiate between canceled and completed if they have the same result? It would also call the onDidCancel
callback.
[Alex Tugarev]
onDidCancel
will be called indeed. OTOH, this callback was introduced in an earlier PR just to complete vscode API compatibility without using promises to do the same thing, i.e. you don’t need to use that callback, because you’re already using the result promise.
[Hanksha]
Yes but the problem remains, in the example code I provided I would not be able to distinguish between user cancelled and progress completed if I added if(n === 10) progress.cancel()
.