本文整理匯總了TypeScript中spica/cancellation.Cancellation類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Cancellation類的具體用法?TypeScript Cancellation怎麽用?TypeScript Cancellation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Cancellation類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: Error
.fmap(async config => {
void event.original.preventDefault();
void process.cast('', new Error(`Aborted.`));
const cancellation = new Cancellation<Error>();
const kill = process.register('', e => {
void kill();
void cancellation.cancel(e);
return new Promise<never>(() => undefined);
}, undefined);
const [scripts] = await env;
window.history.scrollRestoration = 'manual';
//void progressbar(config.progressbar);
return router(config, event, { process: cancellation, scripts }, io)
.then(m => m
.fmap(async ([ss, p]) => (
void kill(),
void docurl.sync(),
void ss
.filter(s => s.hasAttribute('src'))
.forEach(s =>
void scripts.add(new URL(standardize(s.src)).reference)),
void (await p)
.filter(s => s.hasAttribute('src'))
.forEach(s =>
void scripts.add(new URL(standardize(s.src)).reference))))
.extract())
.catch(reason => (
void kill(),
void docurl.sync(),
window.history.scrollRestoration = 'auto',
!cancellation.canceled || reason instanceof FatalError
? void config.fallback(currentTargets.get(event.original) as RouterEventSource, reason)
: undefined));
})
示例3: 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());
});
示例4: kill
const kill = process.register('', e => {
void kill();
void cancellation.cancel(e);
return new Promise<never>(() => undefined);
}, undefined);