UNPKG

stream-chain

Version:

Chain functions, generators, Node streams, and Web streams into a pipeline with backpressure support.

18 lines (14 loc) 595 B
// @ts-self-types="./drain.d.ts" // Drains an async iterable, returning its last yielded value (or `undefined` // if it yielded nothing). The standard way to run a `gen([…])(value)` pipeline // whose output you don't otherwise want: sink-terminated chains // (e.g. `gen([…, asyncBlockWriter(path)])`) yield nothing and resolve to // `undefined`; single-final-value termini (an assembler-style stage that // yields once) come through as the resolved value. const drain = async g => { let last; for await (const v of g) last = v; return last; }; export default drain; export {drain};