Promise Pool Showcase
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 { PromisePool } = require("@supercharge/promise-pool"); | |
const { products } = require("./products"); | |
async function execute() { | |
const { results } = await PromisePool.for(products) | |
.withConcurrency(10) | |
.process(importProduct); | |
console.log(results); | |
} | |
async function importProduct(data, index) { | |
const result = await createProduct(data, index); | |
console.log(result); | |
return result; | |
} | |
async function createProduct(data, index) { | |
const dummyProcessDelay = data.rating * 100; | |
return new Promise((resolve) => | |
setTimeout(() => { | |
resolve({ item: index, delay: dummyProcessDelay }); | |
}, dummyProcessDelay) | |
); | |
} | |
execute(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Complete Git repo: https://github.com/priyankatgit/promise-pool-demo