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

it-pushable

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-pushable

Pushable iterable

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
decreased by-52.84%
Maintainers
2
Weekly downloads
 
Created
Source

it-pushable

Build Status Dependencies Status JavaScript Style Guide

An iterable that you can push values into

Install

npm install it-pushable

Usage

import { pushable } from 'it-pushable'

const source = pushable()

setTimeout(() => source.push('hello'), 100)
setTimeout(() => source.push('world'), 200)
setTimeout(() => source.end(), 300)

const start = Date.now()

for await (const value of source) {
  console.log(`got "${value}" after ${Date.now() - start}ms`)
}
console.log(`done after ${Date.now() - start}ms`)

/*
Output:
got "hello" after 105ms
got "world" after 207ms
done after 309ms
*/
import { pushableV } from 'it-pushable'
import all from 'it-all'

const source = pushableV()

source.push(1)
source.push(2)
source.push(3)
source.end()

console.info(await all(source))
/*
Output:
[ [1, 2, 3] ]
*/

API

pushable([options])

Create a new async iterable. The values yielded from calls to .next() or when used in a for await of loop are "pushed" into the iterable. Returns an async iterable object with the following additional methods:

  • .push(value) - push a value into the iterable. Values are yielded from the iterable in the order they are pushed. Values not yet consumed from the iterable are buffered
  • .end([err]) - end the iterable after all values in the buffer (if any) have been yielded. If an error is passed the buffer is cleared immediately and the next iteration will throw the passed error
  • .readableLength - a number that represents the size of the queue. if objectMode is true, this is the number of objects in the queue, if false it's the total number of bytes in the queue

options is an optional parameter, an object with the following properties:

  • onEnd - a function called after all values have been yielded from the iterator (including buffered values). In the case when the iterator is ended with an error it will be passed the error as a parameter.
  • objectMode - a boolean value that means non-Uint8Arrays will be passed to .push, default: false

pushableV([options])

Similar to pushable, except it yields multiple buffered chunks at a time. All values yielded from the iterable will be arrays.

  • it-pipe Utility to "pipe" async iterables together

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

Keywords

FAQs

Package last updated on 02 Aug 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