-
-
Save flockonus/4a22eda05435be00c209e1183437a111 to your computer and use it in GitHub Desktop.
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
const Bluebird = require('bluebird'); | |
// https://github.com/charto/cwait | |
const { TaskQueue } = require('cwait'); | |
// https://github.com/ForbesLindesay/throat | |
const throat = require('throat')(Bluebird); | |
const list = new Array(300).fill(0).map((x, i) => i); | |
async function job(i) { | |
console.log('>', i, new Date()); | |
return new Promise(function(resolve) { | |
setTimeout(resolve, i % 2 === 0 ? 1 : 100, i); | |
}); | |
} | |
async function run1() { | |
var queue = new TaskQueue(Bluebird, 3); | |
const res = await Bluebird.map(list, queue.wrap(job)); | |
console.log('>>', res); | |
} | |
async function run2() { | |
// const queue = throat(3); | |
const res = await Promise.all(list.map(throat(3, x => job(x)))); | |
console.log('>>', res); | |
} | |
// TODO another one with bluebird? | |
run1().then(console.log, console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment