UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

29 lines 704 B
/** * Hold up a stream until a promise resolves. If it errors, * the error will be emitted to the stream. * * @group Transformers * @example * ``` * ----a-------b------| * * interpose(async () => await setTimeout(50)) * * --------a--------b-| * ``` */ export function interpose(promise) { const fn = typeof promise === 'function' ? promise : () => promise; return new TransformStream({ async transform(chunk, controller) { try { await fn(chunk); } catch (error) { return controller.error(error); } controller.enqueue(chunk); }, }); } //# sourceMappingURL=interpose.js.map