Detalhes do pacote

it-pair

alanshaw169kApache-2.0 OR MIT2.0.6

pair a source async iterable stream and a sink async iterable stream

readme (leia-me)

it-pair

codecov CI

pair a source async iterable stream and a sink async iterable stream

Table of contents

Install

$ npm i it-pair

Browser <script> tag

Loading this module through a script tag will make it's exports available as ItPair in the global namespace.

<script src="https://unpkg.com/it-pair/dist/index.min.js"></script>

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

//read values into this sink...
pipe([1, 2, 3], p.sink)

//but that should become the source over here.
const values = await pipe(p.source, async source => {
  const values = []
  for await (const value of source) {
    values.push(value)
  }
  return value
})

console.log(values) //[1, 2, 3]

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

//the "client": pipe to the first duplex and get the response.
pipe(
  [1,2,3],
  d[0],
  source => {
    for await (value of source) {
      console.log(value) // => 10, 20, 30
    }
  }
)

//the "server": pipe from the second stream back to itself
//(in this case) appling a transformation.
pipe(
  d[1],
  source => (async function * () {
    for await (const e of source) {
      yield e*10
    }
  })(),
  d[1]
)

API Docs

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.

changelog (log de mudanças)

2.0.6 (2023-04-18)

Dependencies

  • bump it-stream-types from 1.0.5 to 2.0.1 (#55) (818f1e4)

2.0.5 (2023-04-17)

Dependencies

  • dev: bump it-all from 2.0.1 to 3.0.1 (#54) (edfe28b)
  • dev: bump it-drain from 2.0.1 to 3.0.1 (#52) (e968d2c)
  • dev: bump it-pipe from 2.0.5 to 3.0.1 (#56) (cbee5ea)

2.0.4 (2023-02-23)

Dependencies

  • dev: bump aegir from 37.12.1 to 38.1.6 (#48) (9f40de3)
  • dev: bump it-all from 1.0.6 to 2.0.0 (#36) (882788b)
  • dev: bump it-drain from 1.0.5 to 2.0.0 (#35) (5f0dcaf)

2.0.3 (2022-08-10)

Bug Fixes

Trivial Changes

2.0.2 (2022-01-13)

Bug Fixes

2.0.1 (2022-01-12)

Trivial Changes

2.0.0 (2022-01-12)

⚠ BREAKING CHANGES

  • switch to named exports, ESM only

Features

Trivial Changes

  • fix: correct reference to pull-stream (#1) (7a0cd69)