New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

for-emit-of

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

for-emit-of - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

4

dist/index.d.ts

@@ -35,2 +35,6 @@ /// <reference types="node" />

transform?: (buffer: Buffer) => T;
/**
* Max number of items to be yielded. If not informed, it'll yield all items of the iterable.
*/
limit?: number;
}

@@ -37,0 +41,0 @@ declare type SuperEmitter = (EventEmitter | Readable | Writable) & {

32

dist/index.js

@@ -10,6 +10,6 @@ "use strict";

var _sleep = require("./sleep");
var _timeout = require("./timeout");
var _sleep = require("./sleep");
const defaults = {

@@ -122,11 +122,18 @@ event: "data",

const removeListeners = () => {
emitter.removeListener(options.event, eventListener);
emitter.removeListener(options.error, errorListener);
options.end.forEach(event => emitter.removeListener(event, endListener));
};
emitter.on(options.event, eventListener);
emitter.once(options.error, errorListener);
options.end.forEach(event => {
emitter.once(event, endListener);
});
options.end.forEach(event => emitter.once(event, endListener));
const getRaceItems = raceFactory(options, emitter);
async function* generator() {
while (events.length || active) {
let shouldYield = true;
let countEvents = 0;
while (shouldYield && (events.length || active)) {
if (error) {

@@ -136,3 +143,3 @@ throw error;

while (events.length > 0) {
while (shouldYield && events.length > 0) {
/* We do not want to block the process!

@@ -146,2 +153,7 @@ This call allows other processes

yield options.transform ? options.transform(event) : event;
countEvents++;
if (options.limit && countEvents >= options.limit) {
shouldYield = false;
}
}

@@ -153,5 +165,3 @@

if (winner === _timeout.timedOut) {
emitter.removeListener(options.event, eventListener);
emitter.removeListener(options.error, errorListener);
options.end.forEach(event => emitter.removeListener(event, endListener));
removeListeners();
throw Error("Event timed out");

@@ -161,2 +171,4 @@ }

}
removeListeners();
}

@@ -163,0 +175,0 @@

{
"name": "for-emit-of",
"version": "1.1.1",
"version": "1.2.0",
"description": "Turn Node.js Events into Async Iterables",

@@ -60,2 +60,2 @@ "main": "./dist/index.js",

}
}
}

@@ -10,2 +10,11 @@ # for-emit-of

- [Example](#example)
- [Transform](#transform)
- [Change the event](#change-the-event)
- [Change the end](#change-the-end)
- [Timeout](#timeout)
- [`firstEventTimeout`](#firsteventtimeout)
- [`inBetweenTimeout`](#inbetweentimeout)
- [Limit](#limit)
# Example

@@ -126,2 +135,28 @@ ```javascript

}
```
# Limit
```js
import forEmitOf from 'for-emit-of';
import { EventEmitter } from "events";
const emitter = new EventEmitter();
const iterator = forEmitOf(emitter, {
limit: 10
});
const interval = setInterval(() => {
emitter.emit("data", {});
}, 100);
let msgCount = 0;
for await (const msg of iterator) {
msgCount += 1
}
clearInterval(interval);
console.log(msgCount); // 10
```
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