Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Tiny extension for native Promises to make them more suitable for Node core APIs.
Tiny extension for native Promises to make them more suitable for Node core APIs.
The package exposes a subclass of the built-in Promise
, which extends that with the following four methods.
new Deferred([executor])
Unlike Promise
, Deferred
does not require an executor function for instantiation, because it makes possible to
resolve or reject the instance from outside the executor's scope.
const d1 = new Deferred,
d2 = new Deferred(executor)
d1.resolve('sun is shining')
function executor(resolve, reject) {
reject('baby is crying') // same as d2.reject(...)
}
d1.then(result => console.log('success:', result))
d2.catch(error => console.error('error:', error))
Output:
success: sun is shining
error: baby is crying
deferred.resolve(value)
Resolve the deferred instance.
deferred.reject(reason)
Reject the deferred instance.
deferred.done(callback)
Attach an error-first callback to the instance. It will be fired once the instance resolves or rejects.
const d1 = new Deferred,
d2 = new Deferred
function handler(err, result) {
if (err)
console.error('error:', err)
else
console.log('success:', result)
}
d1.done(handler)
d2.done(handler)
d1.resolve('your pizza order has arrived')
d2.reject('something exploded')
Output:
success: your pizza order has arrived
error: something exploded
deferred.callback()
Generate an error-first callback which will resolve or reject the instance based on the first parameter passed to it.
const d1 = new Deferred,
d2 = new Deferred,
cb1 = d1.callback(),
cb2 = d2.callback()
d1.then(result => console.log('success:', result))
d2.catch(error => console.error('error:', error))
cb1(null, 'your cat is purring')
cb2('coffee machine is out of order')
Output:
success: your cat is purring
error: coffee machine is out of order
With npm:
npm install defd
Run unit tests:
npm test
Run unit tests and create coverage report:
npm run cover
FAQs
Tiny extension for native Promises to make them more suitable for Node core APIs.
The npm package defd receives a total of 0 weekly downloads. As such, defd popularity was classified as not popular.
We found that defd demonstrated a not healthy version release cadence and project activity because the last version was released 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
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.