https://github.com/jacobbubu/pull-pair
https://github.com/jacobbubu/pull-pair
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jacobbubu/pull-pair
- Owner: jacobbubu
- License: mit
- Created: 2020-03-28T09:17:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-10T01:18:04.000Z (about 2 years ago)
- Last Synced: 2025-01-13T02:30:02.095Z (6 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.13 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# @jacobbubu/pull-pair
[](https://travis-ci.org/jacobbubu/pull-pair)
[](https://coveralls.io/github/jacobbubu/pull-pair)
[](https://www.npmjs.com/package/@jacobbubu/pull-pair/)> Rewritten [pull-pair](https://github.com/dominictarr/pull-pair) in TypeScript.
# pull-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.
``` js
import * as pull from 'pull-stream'
import { pair } from '@jacobbubu/pull-pair'const pa = pair()
// Read values into this sink...
pull(pull.values([1, 2, 3]), pa.sink)// But that should become the source over here.
pull(pa.source, pull.collect(function (err, values) {
if(err) throw err
console.log(values) //[1, 2, 3]
}))```
This is particularly useful for creating duplex streams especially
around servers. Use `pull-pair/duplex` to get two duplex streams
that are attached to each other.``` js
import { duplex } from '@jacobbubu/pull-pair'const dup = duplex()
// The "client": pipe to the first duplex and get the response.
pull(
pull.values([1,2,3]),
dup[0],
pull.collect(console.log) // => 10, 20, 30
)// The "server": pipe from the second stream back to itself
// (in this case) applying a transformation.
pull(
dup[1],
pull.map(function (e) {
return e*10
}),
dup[1]
)
```