Long running task

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?

[original thread by psdutkiewicz]

[Hanksha]

You can use MessageService from @theia/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() {}

[Hanksha]

[psdutkiewicz]

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.

[Hanksha]

You can use a JSON-RPC service that will send the progress update to the frontend which will use the MessageService to display it.

[Hanksha]

Actually I remember vaguely that you could call the MessageService from the backend but it doesn’t seem to work anymore.