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