当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript AtomicPromise.all方法代码示例

本文整理汇总了TypeScript中spica/promise.AtomicPromise.all方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AtomicPromise.all方法的具体用法?TypeScript AtomicPromise.all怎么用?TypeScript AtomicPromise.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spica/promise.AtomicPromise的用法示例。


在下文中一共展示了AtomicPromise.all方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: concat

 .fmap(([ss2, ap2]) =>
   AtomicPromise.all([as1, Right<Error, HTMLScriptElement[]>(ss2), ap2])
     .then(sst =>
       sst.reduce((m1, m2) =>
         m1.bind(s1 =>
           m2.fmap(s2 =>
             concat(s1, s2))))))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:7,代码来源:script.ts

示例2: Event

 m2.fmap(([[, sp], seqD]) =>
   // Asynchronously wait for load completion of elements and scripts.
   void AtomicPromise.all([cp, sp])
     .then(process.either)
     .then(m => m
       .fmap(([events]) => (
         void window.dispatchEvent(new Event('pjax:load')),
         void config.sequence.load(seqD, events)))
       .extract(() => undefined))))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:update.ts

示例3: tuple

 .fmap(([sp, ap]) =>
   AtomicPromise.all(sp)
     .then(m => Either.sequence(m))
     .then(sm =>
       sm.fmap(ss => tuple([
         ss,
         Promise.all(ap)
           .then(m => Either.sequence(m))
       ]))));
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:script.ts

示例4:

 .fmap(([as, ps]) =>
   [as, AtomicPromise.all(ps)] as const)))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:2,代码来源:update.ts

示例5:

 .fmap(([script, code]) =>
   io.evaluate(script, code, selector.logger, skip, AtomicPromise.all(sp), cancellation))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:2,代码来源:script.ts

示例6: script

export function script(
  documents: {
    src: Document;
    dst: Document;
  },
  skip: ReadonlySet<URL.Reference<StandardURL>>,
  selector: {
    ignore: string;
    reload: string;
    logger: string;
  },
  timeout: number,
  cancellation: Cancellee<Error>,
  io = {
    fetch,
    evaluate,
  }
): AtomicPromise<Result> {
  const scripts = find(documents.src, 'script')
    .filter(el => !el.type || /(?:application|text)\/(?:java|ecma)script|module/i.test(el.type))
    .filter(el => !el.matches(selector.ignore.trim() || '_'))
    .filter(el =>
      el.hasAttribute('src')
        ? !skip.has(new URL(standardize(el.src)).reference) || el.matches(selector.reload.trim() || '_')
        : true);
  const { ss, as } = scripts.reduce((o, script) => {
    switch (true) {
      case script.matches('[src][async], [src][defer]'):
        void o.as.push(script);
        break;
      default:
        void o.ss.push(script);
    }
    return o;
  }, {
      ss: [] as HTMLScriptElement[],
      as: [] as HTMLScriptElement[],
    });
  return AtomicPromise.all([
    AtomicPromise.all(request(ss)).then(run),
    AtomicPromise.all(request(as)).then(run),
  ])
    .then(async ([sm, am]) =>
      sm.fmap(async p => (await p)
        .fmap(([ss1, ap1]) =>
          [
            ss1,
            ap1.then(async as1 =>
              am.fmap(async p => (await p)
                .fmap(([ss2, ap2]) =>
                  AtomicPromise.all([as1, Right<Error, HTMLScriptElement[]>(ss2), ap2])
                    .then(sst =>
                      sst.reduce((m1, m2) =>
                        m1.bind(s1 =>
                          m2.fmap(s2 =>
                            concat(s1, s2))))))
                .extract<Either<Error, HTMLScriptElement[]>>(Left))
                .extract<Either<Error, HTMLScriptElement[]>>(Left)),
          ]))
        .extract<Result>(Left));

  function request(scripts: HTMLScriptElement[]): Promise<Either<Error, FetchData>>[] {
    return scripts
      .map(script =>
        io.fetch(script, timeout));
  }

  function run(responses: Either<Error, FetchData>[]): Either<Error, AtomicPromise<Result>> {
    return responses
      .reduce(
        (results, m) => m.bind(() => results),
        responses
          .reduce((results, m) =>
            results
              .bind(cancellation.either)
              .bind(([sp, ap]) => m
                .fmap(([script, code]) =>
                  io.evaluate(script, code, selector.logger, skip, AtomicPromise.all(sp), cancellation))
                .bind(m =>
                  m.extract(
                    p => Right(tuple([concat(sp, [p]), ap])),
                    p => Right(tuple([sp, concat(ap, [p])])))))
        , Right<Error, [AtomicPromise<Either<Error, HTMLScriptElement>>[], AtomicPromise<Either<Error, HTMLScriptElement>>[]]>([[], []])))
      .fmap(([sp, ap]) =>
        AtomicPromise.all(sp)
          .then(m => Either.sequence(m))
          .then(sm =>
            sm.fmap(ss => tuple([
              ss,
              Promise.all(ap)
                .then(m => Either.sequence(m))
            ]))));
  }
}
开发者ID:falsandtru,项目名称:pjax-api,代码行数:94,代码来源:script.ts


注:本文中的spica/promise.AtomicPromise.all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。