Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin] withProgress should start task immediately #6123

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/plugin-ext/src/plugin/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CancellationToken, Progress, ProgressOptions } from '@theia/plugin';
import { RPCProtocol } from '../common/rpc-protocol';
import { CancellationTokenSource } from '@theia/core/lib/common/cancellation';
import { ProgressLocation } from './types-impl';
import { Deferred } from '@theia/core/lib/common/promise-util';

export class NotificationExtImpl implements NotificationExt {
private readonly proxy: NotificationMain;
Expand All @@ -31,15 +32,18 @@ export class NotificationExtImpl implements NotificationExt {
options: ProgressOptions,
task: (progress: Progress<{ message?: string; increment?: number }>, token: CancellationToken) => PromiseLike<R>
): Promise<R> {
const id = new Deferred<string>();
const tokenSource = new CancellationTokenSource();
const progress = task({ report: async item => this.proxy.$updateProgress(await id.promise, item)}, tokenSource.token);
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
const title = options.title ? options.title : '';
const location = this.mapLocation(options.location);
const id = await this.proxy.$startProgress({ title, location });
const tokenSource = new CancellationTokenSource();
const stop = () => {
this.proxy.$stopProgress(id);
};
const progress = task({ report: item => this.proxy.$updateProgress(id, item)}, tokenSource.token);
progress.then(stop, stop);
id.resolve(await this.proxy.$startProgress({ title, location }));
const stop = async () => this.proxy.$stopProgress(await id.promise);
const promise = Promise.all([
progress,
new Promise(resolve => setTimeout(resolve, 250)) // try to show even if it's done immediately
]);
promise.then(stop, stop);
return progress;
}

Expand Down