Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
perf: adding batching promise overflow example
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const { task, sleep } = require('./util') | ||
|
||
async function getUsers(ids) { | ||
const tasks = ids.map(id => task({ result: { name: `bob-${id}`, id }, wait: 10000 })) | ||
return Promise.all(tasks) | ||
} | ||
|
||
const batchSize = 1E4 / 10 | ||
|
||
;(async function startCreatingPromises() { | ||
const ITER = 1E4 | ||
const ids = new Array(ITER) | ||
for (var i = 0; i < ITER; i++) { | ||
if (i % batchSize === 0) await sleep(2000) | ||
ids[i] = i | ||
} | ||
|
||
const users = await getUsers(ids) | ||
console.log(users) | ||
})() |