mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
withStatusBarProgress API and implementation
This commit is contained in:
46
src/vs/workbench/api/node/extHostProgress.ts
Normal file
46
src/vs/workbench/api/node/extHostProgress.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Progress, CancellationToken } from 'vscode';
|
||||
import { MainThreadProgressShape } from './extHost.protocol';
|
||||
|
||||
export class ExtHostProgress {
|
||||
|
||||
private _proxy: MainThreadProgressShape;
|
||||
private _handles: number = 0;
|
||||
|
||||
constructor(proxy: MainThreadProgressShape) {
|
||||
this._proxy = proxy;
|
||||
}
|
||||
|
||||
withStatusBarProgress<R>(task: (progress: Progress<string>, token: CancellationToken) => Thenable<R>): Thenable<R> {
|
||||
const handle = this._handles++;
|
||||
|
||||
this._proxy.$progressStart(handle);
|
||||
const progress = {
|
||||
report: (message: string) => {
|
||||
this._proxy.$progressReport(handle, message);
|
||||
}
|
||||
};
|
||||
|
||||
let p: Thenable<R>;
|
||||
|
||||
try {
|
||||
p = task(progress, null);
|
||||
} catch (err) {
|
||||
this._proxy.$progressEnd(handle);
|
||||
throw err;
|
||||
}
|
||||
|
||||
return p.then(result => {
|
||||
this._proxy.$progressEnd(handle);
|
||||
return result;
|
||||
}, err => {
|
||||
this._proxy.$progressEnd(handle, err);
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user