Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queueLimit #15

Open
danstarns opened this issue Aug 11, 2020 · 2 comments
Open

queueLimit #15

danstarns opened this issue Aug 11, 2020 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@danstarns
Copy link
Member

danstarns commented Aug 11, 2020

Ability to limit the in-memory events held in the 'events array', if the array is at 'capacity' new events will be dropped (not pushed onto the array).

Example Definition

interface Options {
  /**
   * Number of items to be held in memory.
   */
  queueLimit?: number;
  ...
}

Example

const forEmitOf = require("../dist");
const { EventEmitter } = require("events");

async function main() {
  const emitter = new EventEmitter();

  const iterator = forEmitOf(emitter, {
    queueLimit: 3,
  });

  emitter.emit("data", 1);
  emitter.emit("data", 2);
  emitter.emit("data", 3);
  emitter.emit("data", 4); // DISCARDED

  const first = await iterator.next();
  const second = await iterator.next();
  const third = await iterator.next();
  const forth = await iterator.next(); // null? 🤔
}

main();
@Farenheith
Copy link
Contributor

Farenheith commented Aug 11, 2020

What do you think about instead of memoryLimit the property being called queueLImit?

Edit:
About the fourth next(), I think the expected behavior is for it waits until a new event is emitted... in that case, as the keepAlive is not in use, the execution would end

@danstarns
Copy link
Member Author

@Farenheith I like queueLImit makes more sense & thanks for clarifying my '🤔' was not sure the exact behavior.

@danstarns danstarns changed the title in memory limit queueLimit Aug 12, 2020
@danstarns danstarns added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants