本文整理汇总了TypeScript中vs/base/common/winjs.base.TPromise.join方法的典型用法代码示例。如果您正苦于以下问题:TypeScript base.TPromise.join方法的具体用法?TypeScript base.TPromise.join怎么用?TypeScript base.TPromise.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/base/common/winjs.base.TPromise
的用法示例。
在下文中一共展示了base.TPromise.join方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('Delayer - last task should be the one getting called', function () {
let factoryFactory = (n: number) => () => {
return TPromise.as(n);
};
let delayer = new async.Delayer(0);
let promises: TPromise[] = [];
assert(!delayer.isTriggered());
promises.push(delayer.trigger(factoryFactory(1)).then((n) => { assert.equal(n, 3); }));
promises.push(delayer.trigger(factoryFactory(2)).then((n) => { assert.equal(n, 3); }));
promises.push(delayer.trigger(factoryFactory(3)).then((n) => { assert.equal(n, 3); }));
const p = TPromise.join(promises).then(() => {
assert(!delayer.isTriggered());
});
assert(delayer.isTriggered());
return p;
});
示例2: if
export const DEFAULT_TERMINAL_LINUX_READY = new TPromise<string>(c => {
if (env.isLinux) {
TPromise.join([pfs.exists('/etc/debian_version'), process.lazyEnv]).then(([isDebian]) => {
if (isDebian) {
c('x-terminal-emulator');
} else if (process.env.DESKTOP_SESSION === 'gnome' || process.env.DESKTOP_SESSION === 'gnome-classic') {
c('gnome-terminal');
} else if (process.env.DESKTOP_SESSION === 'kde-plasma') {
c('konsole');
} else if (process.env.COLORTERM) {
c(process.env.COLORTERM);
} else if (process.env.TERM) {
c(process.env.TERM);
} else {
c('xterm');
}
});
return;
}
c('xterm');
});
示例3: test
test('Throttler - cancel the first queued promise should not cancel other promises', function () {
let count = 0;
let factory = () => {
return TPromise.timeout(0).then(() => {
return ++count;
});
};
let throttler = new async.Throttler();
let p2: TPromise;
const p = TPromise.join([
throttler.queue(factory).then((result) => { assert.equal(result, 1); }, () => { assert(false, 'should not be here, 1'); }),
p2 = throttler.queue(factory).then((result) => { assert(false, 'should not be here, 2'); }, () => { assert(true, 'yes, it was cancelled'); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }, () => { assert(false, 'should not be here, 3'); }),
throttler.queue(factory).then((result) => { assert.equal(result, 2); }, () => { assert(false, 'should not be here, 4'); })
]);
p2.cancel();
return p;
});
示例4: computeFixes
private computeFixes(range: IMarker | EditorCommon.IRange): TPromise<IQuickFix2[]> {
let model = this.editor.getModel();
if (!QuickFixRegistry.has(model)) {
return TPromise.as(null);
}
if (this.quickFixRequestPromise && range === this.quickFixRequestPromiseRange) {
return this.quickFixRequestPromise;
}
if (this.quickFixRequestPromise) {
this.quickFixRequestPromise.cancel();
this.quickFixRequestPromise = null;
}
this.quickFixRequestPromiseRange = range;
let quickFixes: IQuickFix2[] = [];
let promises = QuickFixRegistry.all(model).map(support => {
return support.getQuickFixes(model.getAssociatedResource(), range).then(result => {
if (!Array.isArray(result)) {
return
}
for (let fix of result) {
quickFixes.push({
id: fix.id,
label: fix.label,
documentation: fix.documentation,
score: fix.score,
support
});
}
}, err => {
errors.onUnexpectedError(err);
});
});
this.quickFixRequestPromise = TPromise.join(promises).then(() => quickFixes);
return this.quickFixRequestPromise;
}
示例5: return
return () => {
// stop when we have a result
if (hasResult) {
return;
}
// for each support in the group ask for suggestions
return TPromise.join(supports.map(support => {
if (!isFalsyOrEmpty(onlyFrom) && onlyFrom.indexOf(support) < 0) {
return;
}
return asWinJsPromise(token => support.provideCompletionItems(model, position, token)).then(container => {
const len = result.length;
if (container && !isFalsyOrEmpty(container.suggestions)) {
for (let suggestion of container.suggestions) {
if (acceptSuggestion(suggestion)) {
fixOverwriteBeforeAfter(suggestion, container);
result.push({
container,
suggestion,
support,
resolve: createSuggestionResolver(support, suggestion, model, position)
});
}
}
}
if (len !== result.length && support !== snippetSuggestSupport) {
hasResult = true;
}
}, onUnexpectedError);
}));
};
示例6: getDocumentSymbols
export function getDocumentSymbols(model: ITextModel): TPromise<DocumentSymbol[]> {
let roots: DocumentSymbol[] = [];
let promises = DocumentSymbolProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideDocumentSymbols(model, token)).then(result => {
if (Array.isArray(result)) {
roots.push(...result);
}
}, err => {
onUnexpectedExternalError(err);
});
});
return TPromise.join(promises).then(() => {
let flatEntries: DocumentSymbol[] = [];
flatten(flatEntries, roots, '');
flatEntries.sort(compareEntriesUsingStart);
return flatEntries;
});
}
示例7: test
test('Limiter - sync', function () {
let factoryFactory = (n: number) => () => {
return TPromise.as(n);
};
let limiter = new Async.Limiter(1);
let promises: TPromise[] = [];
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => promises.push(limiter.queue(factoryFactory(n))));
return TPromise.join(promises).then((res) => {
assert.equal(10, res.length);
limiter = new Async.Limiter(100);
promises = [];
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(n => promises.push(limiter.queue(factoryFactory(n))));
return TPromise.join(promises).then((res) => {
assert.equal(10, res.length);
});
});
});
示例8: getCodeActions
export function getCodeActions(model: ITextModel, range: Range, scope?: CodeActionKind): TPromise<CodeAction[]> {
const allResults: CodeAction[] = [];
const promises = CodeActionProviderRegistry.all(model).map(support => {
return asWinJsPromise(token => support.provideCodeActions(model, range, { only: scope ? scope.value : undefined }, token)).then(result => {
if (Array.isArray(result)) {
for (const quickFix of result) {
if (quickFix) {
if (!scope || (quickFix.kind && scope.contains(quickFix.kind))) {
allResults.push(quickFix);
}
}
}
}
}, err => {
onUnexpectedExternalError(err);
});
});
return TPromise.join(promises).then(
() => allResults.sort(codeActionsComparator)
);
}