How to use the streaming-iterables.take function in streaming-iterables

To help you get started, we’ve selected a few streaming-iterables examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libp2p / js-libp2p / src / identify / index.js View on Github external
async _handlePush ({ connection, stream }) {
    const [data] = await pipe(
      stream,
      lp.decode(),
      take(1),
      toBuffer,
      collect
    )

    let message
    try {
      message = Message.decode(data)
    } catch (err) {
      return log.error('received invalid message', err)
    }

    // Update the listen addresses
    const peerInfo = new PeerInfo(connection.remotePeer)

    try {
      IdentifyService.updatePeerAddresses(peerInfo, message.listenAddrs)
github libp2p / js-libp2p-websockets / test / browser.js View on Github external
it('many writes', async function () {
      this.timeout(10000)
      const s = goodbye({
        source: pipe(
          {
            [Symbol.iterator] () { return this },
            next: () => ({ done: false, value: Buffer.from(Math.random().toString()) })
          },
          take(20000)
        ),
        sink: collect
      })

      const result = await pipe(s, conn, s)
      expect(result).to.have.length(20000)
    })
  })
github libp2p / js-libp2p / src / identify / index.js View on Github external
async identify (connection) {
    const { stream } = await connection.newStream(MULTICODEC_IDENTIFY)
    const [data] = await pipe(
      stream,
      lp.decode(),
      take(1),
      toBuffer,
      collect
    )

    if (!data) {
      throw errCode(new Error('No data could be retrieved'), codes.ERR_CONNECTION_ENDED)
    }

    let message
    try {
      message = Message.decode(data)
    } catch (err) {
      throw errCode(err, codes.ERR_INVALID_MESSAGE)
    }

    let {

streaming-iterables

A collection of utilities for async iterables. Designed to replace your streams.

MIT
Latest version published 1 year ago

Package Health Score

67 / 100
Full package analysis