Skip to content

Instantly share code, notes, and snippets.

@jsmrcaga
Created May 10, 2024 12:16
Show Gist options
  • Save jsmrcaga/b3a5ca63b7f67da0561b8e723ed8733f to your computer and use it in GitHub Desktop.
Save jsmrcaga/b3a5ca63b7f67da0561b8e723ed8733f to your computer and use it in GitHub Desktop.
// Tested on node 18
// The result is sequential
function rand_promise(i) {
return new Promise((r) => {
const timeout = Math.random() * 1000;
setTimeout(() => r(i), timeout);
});
}
const max = 15;
async function run() {
for(let i = 0; i < max; i++) {
const result = await rand_promise(i);
console.log('CURRENT RESULT', i);
}
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment