Skip to content

Instantly share code, notes, and snippets.

@vitaly-t
Created November 3, 2022 20:36
Show Gist options
  • Select an option

  • Save vitaly-t/72ef885b61ae5f543e2d858e38cf70de to your computer and use it in GitHub Desktop.

Select an option

Save vitaly-t/72ef885b61ae5f543e2d858e38cf70de to your computer and use it in GitHub Desktop.
//////////////////
// RUN THIS FIRST: npm install [email protected]
//
// The example below crashes NodeJS (it runs out of memory)
// operator source: https://github.com/vitaly-t/iter-ops/blob/wait-cache/src/ops/async/wait-cache.ts
//////////////////
import {map, pipeAsync, waitCache} from 'iter-ops';
function* gen(n) {
while (n > 0) {
yield n--;
}
}
const i = pipeAsync(gen(1_000_000), map(a => Promise.resolve(a)), waitCache(100));
(async function () {
const start = Date.now();
for await(const a of i) {
// console.log(a);
}
console.log('duration:', Date.now() - start);
})();
@vitaly-t
Copy link
Author

vitaly-t commented Nov 3, 2022

A bit more tests, and I'm beginning to see that Promise.race is the culprit, it is godawful slow, and eats up all memory.

There are some outstanding issues about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment