menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Theia

Eclipse Theia - Cloud & Desktop IDE

Channels
Team

Long running task

June 4, 2020 at 9:30am

Long running task

June 4, 2020 at 9:30am
I need to handle (possibly) long running task. It can take from a fraction of a second up to several minutes. I would like to show information about progress and provide an option to cancel this task.
What is the best way in Theia to handle this kind of scenario? I thought about notification bar, but maybe there is a better way?

June 4, 2020 at 10:46am
You can use MessageService from /core.
@inject(MessageService) messageService: MessageService;
async doSomething() {
// get progress object
const progress = await this.messageService.showProgress({
text: "Doing something"
});
// report progress before next unit of work
progress.report({
message: "Doing task 1...",
work: {
done: 0,
total: 2
}
});
// wait for task 1 to complete
await this.task1();
progress.report({
message: "Doing task 2...",
work: {
done: 1,
total: 2
}
});
// wait for task 2 to complete
await this.task2();
// stop showing the progress
progress.cancel();
}
async task1() {}
async task2() {}
Edited
like-fill
1
I am going to have one task which can take a moment to finish in backend. I could use that but I am not sure how to implement progress notifying from backend to frontend.
Edited
You can use a JSON-RPC service that will send the progress update to the frontend which will use the MessageService to display it.
like-fill
1
Actually I remember vaguely that you could call the MessageService from the backend but it doesn't seem to work anymore.