15.4.15 • Published 4 years ago

@the-/stream v15.4.15

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

@the-/stream

npm Version

Base of the streams

Installation

$ npm install @the-/stream --save

Usage

'use strict'

const { TheStream } = require('@the-/stream')

async function tryExample() {
  class CountupStream extends TheStream {
    streamDidOpen() {
      this.counts = 0
    }

    streamWillClose() {
      console.log('Counts', this.counts)
    }

    // Consume values from `stream.push()`
    async consume(provided) {
      for await (const chunk of provided) {
        console.log('pushed', chunk)
        this.counts++
      }
    }

    // Provide values for `stream.pull()`
    async *provide() {
      do {
        yield this.counts--
        console.log('pulled', this.counts)
      } while (this.counts > 0)
    }
  }

  const stream = new CountupStream({})

  await stream.open()

  for (let i = 0; i < 100; i++) {
    await stream.push(i * Math.random())
  }

  console.log(await stream.pull())

  await stream.close()
}

tryExample().catch((err) => console.error(err))

API Guide

See API Guide for more detail

License

This software is released under the MIT License.

Links

15.4.15

4 years ago

15.4.14

4 years ago

15.4.13

4 years ago

15.4.12

5 years ago

15.4.1

5 years ago

15.2.0

5 years ago

15.1.6

5 years ago

15.1.5

5 years ago

15.1.4

5 years ago

15.1.3

5 years ago

15.1.0

5 years ago

15.0.3

5 years ago