當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript cancellation.Cancellation類代碼示例

本文整理匯總了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());
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:34,代碼來源:script.test.ts

示例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));
 })
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:34,代碼來源:router.ts

示例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());
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:17,代碼來源:xhr.test.ts

示例4: kill

 const kill = process.register('', e => {
   void kill();
   void cancellation.cancel(e);
   return new Promise<never>(() => undefined);
 }, undefined);
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:5,代碼來源:router.ts


注:本文中的spica/cancellation.Cancellation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。