-
-
Save priyankatgit/850ad430e00916cebf5779c2ffb6b24e to your computer and use it in GitHub Desktop.
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 { products } = require("./products"); | |
async function execute() { | |
const promises = [] | |
// Running each import product process parallel | |
for await (const data of products) { | |
const importPromise = importProduct(data); | |
promises.push(importPromise) | |
} | |
// Waited to finish all products at once and returns inserted product data from database | |
const importedProducts = await Promise.all(promises) | |
} | |
async function importProduct(data) { | |
return createProduct(data); | |
} | |
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