mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 16:49:06 +01:00
🔼 move thenable<->promise utility to async
This commit is contained in:
@@ -31,24 +31,7 @@ import {FormatRegistry, FormatOnTypeRegistry} from 'vs/editor/contrib/format/com
|
||||
import {CodeLensRegistry} from 'vs/editor/contrib/codelens/common/codelens';
|
||||
import {ParameterHintsRegistry} from 'vs/editor/contrib/parameterHints/common/parameterHints';
|
||||
import {SuggestRegistry} from 'vs/editor/contrib/suggest/common/suggest';
|
||||
|
||||
function isThenable<T>(obj: any): obj is Thenable<T> {
|
||||
return obj && typeof (<Thenable<any>>obj).then === 'function';
|
||||
}
|
||||
|
||||
function asWinJsPromise<T>(callback: (token: vscode.CancellationToken) => T | Thenable<T>): TPromise<T> {
|
||||
let source = new CancellationTokenSource();
|
||||
return new TPromise<T>((resolve, reject) => {
|
||||
let item = callback(source.token);
|
||||
if (isThenable<T>(item)) {
|
||||
item.then(resolve, reject);
|
||||
} else {
|
||||
resolve(item);
|
||||
}
|
||||
}, () => {
|
||||
source.cancel();
|
||||
});
|
||||
}
|
||||
import {asWinJsPromise} from 'vs/base/common/async';
|
||||
|
||||
// --- adapter
|
||||
|
||||
|
||||
Reference in New Issue
Block a user