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

yield many #6

Open
danstarns opened this issue Aug 6, 2020 · 0 comments
Open

yield many #6

danstarns opened this issue Aug 6, 2020 · 0 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 6, 2020

If specified return an array of events. Not to return an array if not specified. yieldMany represents the array capacity, not length.

Feel free to explore other names, yieldMany I'm not sure about

Example definition

interface Options {
  /**
   * Number of items to be yielded. If not specified 1 event (non array) is returned, else an array WHERE `cap` === `yieldMany`.
   */
  yieldMany?: number;
  ...
}

In the wild example

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

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

  const iterator = forEmitOf(emitter, {
    yieldMany: 2,
  });

  setInterval(() => {
    emitter.emit("data", {
      id: uuid(),
    });
  }, 100);

  for await (const [a, b] of iterator) {
    await Promise.all([somePromise(a), somePromise(b)]);
  }
}

main();
@danstarns danstarns added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Aug 6, 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

1 participant