Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.