本文整理匯總了TypeScript中spica/cancellation.Cancellation.cancel方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Cancellation.cancel方法的具體用法?TypeScript Cancellation.cancel怎麽用?TypeScript Cancellation.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類spica/cancellation.Cancellation
的用法示例。
在下文中一共展示了Cancellation.cancel方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('cancel', done => {
let cnt = 0;
const cancellation = new Cancellation<Error>();
script(
{
src: parse(html('head', [html('script', { class: 'test' })]).outerHTML).extract(),
dst: parse('').extract()
},
new Set([]),
{
ignore: '',
reload: '',
logger: 'head'
},
1e3,
cancellation,
{
fetch: async script => {
assert(cnt === 0 && ++cnt);
assert(script.className === 'test');
return Right(tuple([script, '']));
},
evaluate: script => {
assert(++cnt === NaN);
return Left(AtomicPromise.resolve(Right(script)));
},
})
.then(m => {
assert(cnt === 1 && ++cnt);
assert(m.extract(e => e) instanceof Error);
done();
});
cancellation.cancel(new Error());
});
示例2: it
it('cancel', done => {
const cancellation = new Cancellation<Error>();
xhr(
RouterEventMethod.GET,
new URL(standardize('')),
new Headers(),
null,
0,
p => p,
() => '',
cancellation)
.then(m => m.extract(err => {
assert(err instanceof Error);
done();
}));
cancellation.cancel(new Error());
});
示例3: kill
const kill = process.register('', e => {
void kill();
void cancellation.cancel(e);
return new Promise<never>(() => undefined);
}, undefined);