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


TypeScript cancellation.CancellationTokenSource類代碼示例

本文整理匯總了TypeScript中vs/base/common/cancellation.CancellationTokenSource的典型用法代碼示例。如果您正苦於以下問題:TypeScript CancellationTokenSource類的具體用法?TypeScript CancellationTokenSource怎麽用?TypeScript CancellationTokenSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CancellationTokenSource類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

	test('OutlineModel#create, cached/cancel', async function () {

		let model = TextModel.createFromString('foo', undefined, undefined, URI.file('/fome/path.foo'));
		let isCancelled = false;

		let reg = DocumentSymbolProviderRegistry.register({ pattern: '**/path.foo' }, {
			provideDocumentSymbols(d, token) {
				return new Promise(resolve => {
					token.onCancellationRequested(_ => {
						isCancelled = true;
						resolve(null);
					});
				});
			}
		});

		assert.equal(isCancelled, false);
		let s1 = new CancellationTokenSource();
		OutlineModel.create(model, s1.token);
		let s2 = new CancellationTokenSource();
		OutlineModel.create(model, s2.token);

		s1.cancel();
		assert.equal(isCancelled, false);

		s2.cancel();
		assert.equal(isCancelled, true);

		reg.dispose();
	});
開發者ID:burhandodhy,項目名稱:azuredatastudio,代碼行數:30,代碼來源:outlineModel.test.ts

示例2: test

	test('cancel before token', function (done) {

		var source = new CancellationTokenSource();
		assert.equal(source.token.isCancellationRequested, false);
		source.cancel();

		assert.equal(source.token.isCancellationRequested, true);

		source.token.onCancellationRequested(function () {
			assert.ok(true);
			done();
		});
	});
開發者ID:elemongw,項目名稱:vscode,代碼行數:13,代碼來源:cancellation.test.ts

示例3: test

	test('dispose calls no listeners', function () {

		let count = 0;

		let source = new CancellationTokenSource();
		source.token.onCancellationRequested(function () {
			count += 1;
		});

		source.dispose();
		source.cancel();
		assert.equal(count, 0);
	});
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:13,代碼來源:cancellation.test.ts

示例4: test

	test('parent cancels child', function () {

		let parent = new CancellationTokenSource();
		let child = new CancellationTokenSource(parent.token);

		let count = 0;
		child.token.onCancellationRequested(() => count += 1);

		parent.cancel();

		assert.equal(count, 1);
		assert.equal(child.token.isCancellationRequested, true);
		assert.equal(parent.token.isCancellationRequested, true);
	});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:14,代碼來源:cancellation.test.ts

示例5: renderElement

	renderElement(index: number, _: number, data: ITemplateData<TTemplateData>): void {
		data.disposable.dispose();

		const model = this.modelProvider();

		if (model.isResolved(index)) {
			return this.renderer.renderElement(model.get(index), index, data.data);
		}

		const cts = new CancellationTokenSource();
		const promise = model.resolve(index, cts.token);
		data.disposable = { dispose: () => cts.cancel() };

		this.renderer.renderPlaceholder(index, data.data);
		promise.then(entry => this.renderer.renderElement(entry, index, data.data));
	}
開發者ID:developers23,項目名稱:vscode,代碼行數:16,代碼來源:listPaging.ts

示例6: function

	let result = function(...args: any[]) {

		let source = new CancellationTokenSource();

		return new TPromise<T>((c, e) => {

			args.push(source.token);
			let value = callback.apply(context, args);

			if (value && typeof value['then'] === 'function') {
				value.then(c, e);
			} else {
				c(value);
			}

		}, function() {
			source.cancel();
		});
	};
開發者ID:inspiredjw,項目名稱:VisualStudioCode,代碼行數:19,代碼來源:async.ts

示例7:

		data.disposable = { dispose: () => cts.cancel() };
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:1,代碼來源:listPaging.ts


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