本文整理匯總了TypeScript中vs/base/common/cancellation.CancellationTokenSource.cancel方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CancellationTokenSource.cancel方法的具體用法?TypeScript CancellationTokenSource.cancel怎麽用?TypeScript CancellationTokenSource.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vs/base/common/cancellation.CancellationTokenSource
的用法示例。
在下文中一共展示了CancellationTokenSource.cancel方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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();
});
示例2: test
test('token stays the same', function () {
let source = new CancellationTokenSource();
let token = source.token;
assert.ok(token === source.token); // doesn't change on get
source.cancel();
assert.ok(token === source.token); // doesn't change after cancel
source.cancel();
assert.ok(token === source.token); // doesn't change after 2nd cancel
source = new CancellationTokenSource();
source.cancel();
token = source.token;
assert.ok(token === source.token); // doesn't change on get
});
示例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);
});
示例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);
});
示例5:
data.disposable = { dispose: () => cts.cancel() };
示例6: function
}, function() {
source.cancel();
});