Skip to content

Instantly share code, notes, and snippets.

@priyankatgit
Last active August 16, 2022 08:37
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/4d64723d36b3657686fa4b2ce0c45fbb to your computer and use it in GitHub Desktop.
Save priyankatgit/4d64723d36b3657686fa4b2ce0c45fbb to your computer and use it in GitHub Desktop.
Promise Pool Showcase
// Think that we got the list of products to import into database(May be from CSV or external API anything...)
const { products } = require("./products");
async function execute() {
let importedProducts = [];
for await (const data of products) {
const product = await importProduct(data);
importedProducts.push(product);
}
}
async function importProduct(data) {
// Code to import product into database
// Imagine createProduct function creates product into the database and returns the database product instance
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