Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
perf: adding batching promise overflow example
  • Loading branch information
thlorenz committed May 7, 2018
1 parent 3e5fcb5 commit e3615b4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 17-promise-overflow.batches.js
@@ -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)
})()

0 comments on commit e3615b4

Please sign in to comment.