create-tateru-cli
Version:
Create basic Tateru CLI project from template files
22 lines (20 loc) • 483 B
JavaScript
/**
* Create truly async loop over the collection of items.
* @param {array} collection Array of items.
* @param {function} cb Callback function.
*/
export const asyncForLoop = async (collection, cb) => {
const _this = this;
for (let item of collection) {
await new Promise((resolve, reject) => {
setTimeout(() => {
try {
cb.call(_this, item);
resolve();
} catch (e) {
reject(e);
}
}, 0);
});
}
};