15.4.15 • Published 4 years ago
@the-/stream v15.4.15
@the-/stream
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
- module:@the-/stream
- module:@the-/stream.helpers
- TheStream
See API Guide for more detail
License
This software is released under the MIT License.