Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
iterate-promise
Advanced tools
Iterate Promise is an npm package used for synchronizing async loop calls based on 'deasync' blocking mechanism by calling Node.js event loop
Iterate Promise is an npm package used for synchronizing async loop calls based on 'deasync' blocking mechanism by calling Node.js event loop.
While looping through an iterable set, a problem arises when we wish to perform an async task on each item of the set and also perform a task in same sequential order with the response received.
Iterate promise offers a simple and easy solution for this problem.
forEach
function
forEach(iterableSet, onEach, afterEach)
iterableSet
- A data structure that can be iterated.onEach
- Work to perform on each loop iteration (must return a promise)
resolve
having no params and reject
with the error object (see example).afterEach
- Work to perform after each loop async code successfully executes.
Using ES6 syntax
let iPromise = require('iterate-promise');
iPromise.forEach(array, (position) => { //forEach function
return new Promise(
function (resolve, reject) {
request({ //async call
uri: array[position],
method: "GET"
}, (error, result, body) => {
//response from async call
if (error) {
reject(error);
} else {
newArray.push(JSON.parse(body));
resolve();
}
});
}
);
}, (position) => { //afterEach function
console.log(position);
}).then(() => { //after the complete loop successfully executes
console.log("Done");
}).catch((errorObject) => { //if it fails (Read below)
console.log(errorObject.position);
console.log(errorObject.error);
});
forEachWorking
function
forEachWorking(iterableSet, onEach, onEachError,afterEach)
onEachError
- If an error occurs on single item of the iterable set.Using ES6 syntax
let iPromise = require('iterate-promise');
iPromise.forEachWorking(array, (position) => { //forEach function
return new Promise(
function (resolve, reject) {
//todo
}
);
},(position,error) => { //onEachError function
console.log(position + error);
},(position) => { //afterEach function
}).then(() => { //after the complete loop successfully executes
}).catch((errorObject) => {
});
Note : If there is a user defined error anywhere in any function , the execution directly goes to the catch function without working any further
v1.1.0
New : forEachWorking
function will continue working even if a single iteration fails
v1.0.1
Initial release - containing the basic forEach
function only.
ISC Licence
Copyright 2018 Saksham (DawnImpulse)
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
OR PERFORMANCE OF THIS SOFTWARE.
FAQs
Iterate Promise is an npm package used for synchronizing async loop calls based on 'deasync' blocking mechanism by calling Node.js event loop
The npm package iterate-promise receives a total of 0 weekly downloads. As such, iterate-promise popularity was classified as not popular.
We found that iterate-promise 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.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.