Skip to content

Instantly share code, notes, and snippets.

@alexeychikk
Created February 2, 2024 12:00
Show Gist options
  • Save alexeychikk/bdf685d2f354b5067702396cbbfea60d to your computer and use it in GitHub Desktop.
Save alexeychikk/bdf685d2f354b5067702396cbbfea60d to your computer and use it in GitHub Desktop.
Test Promise.all
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
const reportGC = async () => {
global.gc();
await sleep(1000);
console.log('GC\nb() results:\n', process.memoryUsage());
};
let endPromise = Promise.resolve();
const log = async msg => {
await sleep(100);
// console.log('log', msg);
return msg;
};
const logTransport = async msg => {
const logPromise = log(msg);
endPromise = (async () => {
await Promise.all([endPromise, logPromise]);
})();
await logPromise;
};
for (let j = 0; j < 30; j++) {
for (let i = 0; i < 10000; i++) {
logTransport(i);
}
console.log('end', await endPromise);
await reportGC();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment