Socket
Socket
Sign inDemoInstall

make-event-iterator

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    make-event-iterator

Create an iterator from an event emitter


Version published
Weekly downloads
3
Maintainers
1
Install size
10.7 kB
Created
Weekly downloads
 

Readme

Source

Make Event Iterator

Do you have event emitters you are wrapping in a single promise? Is the return from that process massive and causing memory issues? Do you want an excuse to use for await...of?

Create an iterator from an event emitter!

Installation

npm i make-event-iterator

Usage

It is easier than saying, just supply the an event emitter to the package.

const makeEventIterator = require('make-event-iterator');
for await(const chunk of makeEventIterator(eventEmitter)) {
    // ...
}

http server

const http = require('http');
const makeEventIterator = require('make-event-iterator');

async function handleHttp(req, res) {
    for await(const chunk of makeEventIterator(req)) {
        console.log('chunk:', chunk.length);
    }
    res.end();
}

const server = http.createServer(handleHttp);
server.listen(8000);

readline

const fs = require('fs');
const readline = require('readline');
const makeEventIterator = require('make-event-iterator');

const fileStream = fs.createReadStream('file.txt');
const rl = readline.createInterface({
    input: fileStream,
});

for await (const line of makeEventIterator(rl, makeEventIterator.READLINE)) {
    console.log('line:', line);
}

License

Copyright (c) 2021, Michael Szmadzinski. (MIT License)

FAQs

Last updated on 21 Feb 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc