本文整理汇总了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))))))
示例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))))
示例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))
]))));
示例4:
.fmap(([as, ps]) =>
[as, AtomicPromise.all(ps)] as const)))
示例5:
.fmap(([script, code]) =>
io.evaluate(script, code, selector.logger, skip, AtomicPromise.all(sp), cancellation))
示例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))
]))));
}
}