Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
promise-chain-executor
Advanced tools
Executes promises in a chain, allowing results from previous promise to affect following ones
A tool for executing promises in a chain, where the output of previous promises are used to change the behaviour of following promises.
A PromiseSupplier
is passed to the Promise Chain Executor, this supplier is responsible for creating a new Promise
based on the output from the previous Promise.
This can be demonstrated in a simple form with the following example:
const promiseSupplier = async (previousResult:number|null)=> {
const newResult = (previousResult ?? 0) + 1
if (newResult > 9) {
return null
}
return newResult
}
const results = await index.execute<number>(promiseSupplier)
// results: [1,2,3,4,5,6,7,8,9]
This is not a very useful example of the executor, a typical use case for the Promise Chain Executor is when you are calling an API to iterate through some results and you receive an offset ID to continue from.
const promiseSupplier = async (previousOffset:string|null)=> {
const newResults = await callApiForNextResults(previousOffset)
if (newResults.length === 0) {
return null; // if we are at the end of the results, return null to terminate the chain
}
await doSomethingWithResults(newResults)
const lastResult = newResults[newResults.length - 1]
const newOffset = lastResult.id // update the offset to start from the most recent result
return newOffset
}
// process results from API by chaining promises together for each new offset
await index.execute<string>(promiseSupplier)
npm install --save promise-chain-executor
FAQs
Executes promises in a chain, allowing results from previous promise to affect following ones
The npm package promise-chain-executor receives a total of 4 weekly downloads. As such, promise-chain-executor popularity was classified as not popular.
We found that promise-chain-executor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.