Skip to content

Commit

Permalink
👯‍♂️ remove asWinJSPromise #56137
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 7, 2018
1 parent cd87374 commit b71ea76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
29 changes: 0 additions & 29 deletions src/vs/base/common/async.ts
Expand Up @@ -58,35 +58,6 @@ export function createCancelablePromise<T>(callback: (token: CancellationToken)
};
}

export function asWinJsPromise<T>(callback: (token: CancellationToken) => T | TPromise<T> | Thenable<T>): TPromise<T> {
let source = new CancellationTokenSource();
return new TPromise<T>((resolve, reject) => {
let item = callback(source.token);
if (item instanceof TPromise) {
item.then(result => {
source.dispose();
resolve(result);
}, err => {
source.dispose();
reject(err);
});
} else if (isThenable<T>(item)) {
item.then(result => {
source.dispose();
resolve(result);
}, err => {
source.dispose();
reject(err);
});
} else {
source.dispose();
resolve(item);
}
}, () => {
source.cancel();
});
}

export function asThenable<T>(callback: () => T | TPromise<T> | Thenable<T>): Thenable<T> {
return new TPromise<T>((resolve, reject) => {
let item = callback();
Expand Down
9 changes: 5 additions & 4 deletions src/vs/workbench/parts/quickopen/browser/gotoSymbolHandler.ts
Expand Up @@ -26,7 +26,8 @@ import { overviewRulerRangeHighlight } from 'vs/editor/common/view/editorColorRe
import { GroupIdentifier, IEditorInput } from 'vs/workbench/common/editor';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroup } from 'vs/workbench/services/group/common/editorGroupsService';
import { asWinJsPromise } from 'vs/base/common/async';
import { asThenable } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';

export const GOTO_SYMBOL_PREFIX = '@';
export const SCOPE_PREFIX = ':';
Expand Down Expand Up @@ -483,16 +484,16 @@ export class GotoSymbolHandler extends QuickOpenHandler {
if (this.outlineToModelCache[modelId]) {
return TPromise.as(this.outlineToModelCache[modelId]);
}

return asWinJsPromise(token => getDocumentSymbols(<ITextModel>model, token)).then(entries => {
// TODO@Ben - QuickOpenHandler#getResult should support cancellation
return TPromise.wrap(asThenable(() => getDocumentSymbols(<ITextModel>model, CancellationToken.None)).then(entries => {

const model = new OutlineModel(this.toQuickOpenEntries(entries));

this.outlineToModelCache = {}; // Clear cache, only keep 1 outline
this.outlineToModelCache[modelId] = model;

return model;
});
}));
}
}

Expand Down

0 comments on commit b71ea76

Please sign in to comment.