
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
promise-handy-extension
Advanced tools
Some handy extension for es6 promise such as Promise.reduce, Promise.series.
Promise-Handy-Extension is a pretty simple ES6 promise extension. You can use it in node/browser ENV which has implemented Promises/A+ specification.
$ npm install promise-handy-extension
commonJS:
require ('promise-handy-extension');
ES6:
// ES6:
import 'promise-handy-extension';
Use it directly in browse:
<script type="text/javascript" src="../release/promiseHandyExtension.min.js"></script>
...
</script>
Then the Promise object will be extended with these methods:
Promise.series
Promise.reduce
...
// an asyncCall:
function asyncCall(input) {
// which will return a promise;
return Promise.resolve(input);
}
Promise.series([input1, input2, input3], function(input, index) {
return asyncCall(input);
}).then((results)=>{
console.log(results);
// it should be [input1, input2, input3];
});
The key point here for this method is the execution order is guaranteed which means only when the returned promise asyncCall(input1) is resolved, we will execute asyncCall(input2) to get the next promise to execute. This is why it called 'series'.
If one promise is rejected, it will fail fast: Promise.series will reject immediately.
For more detailed example, please check the test case which shows how this handy method can control your promise execute flow:
// an asyncCall:
function asyncCall(input) {
// which will return a promise;
return Promise.resolve(input);
}
Promise.reduce([input1, input2, input3], function(prev, curr, currIdx, arr) {
return asyncCall(current).then(val=> prev + val);
}, 0).then((results)=>{
console.log(results);
// it should be 0 + input1 + input2 + input3;
});
The key point here for this method is the execution order is guaranteed which means only when the returned promise asyncCall(input1) is resolved, we will execute asyncCall(input2) to get the next promise to execute in reduce way.
If one promise is rejected, it will fail fast: Promise.reduce will reject immediately.
For more detailed example, please check the test case which shows how this handy method can control your promise execute flow:
FAQs
Some handy extension for es6 promise such as Promise.reduce, Promise.series.
The npm package promise-handy-extension receives a total of 0 weekly downloads. As such, promise-handy-extension popularity was classified as not popular.
We found that promise-handy-extension 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
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.