Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

it-pair

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-pair

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

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
decreased by-9.69%
Maintainers
2
Weekly downloads
 
Created
Source

it-pair

Build Status Dependencies Status JavaScript Style Guide

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.

var pipe = require('it-pipe')
var pair = require('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.

var DuplexPair = require('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]
)

License

MIT

FAQs

Package last updated on 12 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc