当前位置: 首页>>代码示例>>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;未经允许,请勿转载。