本文整理汇总了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);