Last active
August 16, 2022 08:37
-
-
Save priyankatgit/4d64723d36b3657686fa4b2ce0c45fbb 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
// 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(); |
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