it-pair
pair a source async iterable stream and a sink async iterable stream
Table of contents
Install
$ npm i it-pair
A pair of {source, sink} streams that are internally connected,
(what goes into the sink comes out the source)
This can be used to construct pipelines that are connected.
import { pipe } from 'it-pipe'
import { pair } from 'it-pair'
var p = pair()
pipe([1, 2, 3], p.sink)
const values = await pipe(p.source, async source => {
const values = []
for await (const value of source) {
values.push(value)
}
return value
})
console.log(values)
This is particularly useful for creating duplex streams especially
around servers. Use it-pair/duplex
to get two duplex streams
that are attached to each other.
import { duplexPair } from 'it-pair/duplex'
var d = duplexPair()
pipe(
[1,2,3],
d[0],
source => {
for await (value of source) {
console.log(value)
}
}
)
pipe(
d[1],
source => (async function * () {
for await (const e of source) {
yield e*10
}
})(),
d[1]
)
License
Licensed under either of
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.