Long running task
June 4, 2020 at 9:30amLong running task
June 4, 2020 at 9:30amI 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
@inject(MessageService) messageService: MessageService;async doSomething() {// get progress objectconst progress = await this.messageService.showProgress({text: "Doing something"});// report progress before next unit of workprogress.report({message: "Doing task 1...",work: {done: 0,total: 2}});// wait for task 1 to completeawait this.task1();progress.report({message: "Doing task 2...",work: {done: 1,total: 2}});// wait for task 2 to completeawait this.task2();// stop showing the progressprogress.cancel();}async task1() {}async task2() {}
You can use a JSON-RPC service that will send the progress update to the frontend which will use the
MessageService
to display it.Actually I remember vaguely that you could call the
MessageService
from the backend but it doesn't seem to work anymore.