Skip to content

Instantly share code, notes, and snippets.

@priyankatgit
Last active August 16, 2022 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priyankatgit/850ad430e00916cebf5779c2ffb6b24e to your computer and use it in GitHub Desktop.
Save priyankatgit/850ad430e00916cebf5779c2ffb6b24e to your computer and use it in GitHub Desktop.
Promise Pool Showcase
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();
@priyankatgit
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment