UNPKG

@thi.ng/rstream

Version:

Reactive streams & subscription primitives for constructing dataflow graphs / pipelines

44 lines 1.38 kB
import type { Fn, IID } from "@thi.ng/api"; import { Subscription } from "./subscription.js"; export interface ResolverOpts extends IID<string> { /** * Error handler for failed promises. */ fail: Fn<any, void>; } /** * Creates a {@link Subscription} which receives promises, buffers them * and then passes their resolved values downstream. * * @remarks * If the optional `fail` handler is provided, it'll be called with the * error of each failed promise. If none is provided, the sub's * {@link ISubscriber.error} handler is called, which then stops the sub * from receiving further values. * * @example * ```ts tangle:../export/resolve.ts * import { fromIterable, resolve, trace } from "@thi.ng/rstream"; * import { delayed } from "@thi.ng/transducers"; * * fromIterable([1, 2, 3], { delay: 500 }) * .transform(delayed(1000)) * .subscribe(resolve()) * .subscribe(trace("result")); * // result 1 * // result 2 * // result 3 * // result done * ``` * * @param opts - */ export declare const resolve: <T>(opts?: Partial<ResolverOpts>) => Resolver<T>; export declare class Resolver<T> extends Subscription<Promise<T>, T> { protected outstanding: number; protected fail?: Fn<any, void>; constructor(opts?: Partial<ResolverOpts>); next(x: Promise<T>): void; done(): void; } //# sourceMappingURL=resolve.d.ts.map