當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript base.TPromise.join方法代碼示例

本文整理匯總了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;
	});
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:22,代碼來源:async.test.ts

示例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');
});
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:22,代碼來源:terminal.ts

示例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;
	});
開發者ID:developers23,項目名稱:vscode,代碼行數:22,代碼來源:async.test.ts

示例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;
	}
開發者ID:gaoxiaojun,項目名稱:vscode,代碼行數:39,代碼來源:quickFixModel.ts

示例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);
			}));
		};
開發者ID:rajkumar42,項目名稱:vscode,代碼行數:39,代碼來源:suggest.ts

示例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;
	});
}
開發者ID:developers23,項目名稱:vscode,代碼行數:22,代碼來源:quickOpen.ts

示例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);
			});
		});
	});
開發者ID:liunian,項目名稱:vscode,代碼行數:23,代碼來源:async.test.ts

示例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)
	);
}
開發者ID:JarnoNijboer,項目名稱:vscode,代碼行數:23,代碼來源:quickFix.ts


注:本文中的vs/base/common/winjs.base.TPromise.join方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。