1.0.1 • Published 4 years ago

@jacobbubu/pull-pair v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

@jacobbubu/pull-pair

Build Status Coverage Status npm

Rewritten 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.

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.

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]
)