@freebroccolo/promise-bag

0.0.0 • Public • Published

@freebroccolo/promise-bag

Travis Build Status dependency Status devDependency Status

What is this?

A "bag" of promises which implements the Generator interface. You put the promises in and then observe them in the order in which they resolve. You can think of this as implementing an iterative Promise.race which races a bunch of promises, removes the winner from the pool, and continues racing the remaining promises until the pool is empty.

Example:

async function main() {
  const tasks = new PromiseBag();
  for (let i = 0; i < 10; i++) {
    tasks.put(new Promise((resolve) => setTimeout(() => resolve(i), Math.random() * 100)));
  }
  for (const val of tasks) {
    console.log(await val);
  }
}

Output:

0
4
7
6
8
1
9
5
2
3

Readme

Keywords

none

Package Sidebar

Install

npm i @freebroccolo/promise-bag

Weekly Downloads

0

Version

0.0.0

License

ISC

Last publish

Collaborators

  • freebroccolo