promise_mtd
Advanced tools
Comparing version 1.0.1 to 1.0.2
41
index.js
'use strict'; | ||
const promise_mthds = module.exports; | ||
const promise_mtd = module.exports; | ||
promise_mthds.foreach = promise_mthds.forEach = require('./promise_mtd/foreach.js'); | ||
promise_mtd.foreach = promise_mtd.forEach = require('./promise_mtd/foreach.js'); | ||
promise_mthds.map = require('./promise_mtd/map.js'); | ||
promise_mtd.map = require('./promise_mtd/map.js'); | ||
promise_mthds.transform = require('./promise_mtd/transform.js'); | ||
promise_mtd.transform = require('./promise_mtd/transform.js'); | ||
promise_mthds.while = require('./promise_mtd/while.js'); | ||
promise_mtd.while = require('./promise_mtd/while.js'); | ||
promise_mthds.parallel = require('./promise_mtd/parallel.js') | ||
promise_mtd.parallel = require('./promise_mtd/parallel.js'); | ||
promise_mthds.setImmediate = promise_mthds.set_immediate = require('./promise_mtd/setImmediate.js'); | ||
promise_mtd.all = require('./promise_mtd/all.js'); | ||
promise_mtd.setImmediate = promise_mtd.set_immediate = require('./promise_mtd/setImmediate.js'); | ||
// void async function() { | ||
@@ -38,1 +40,26 @@ // let i = 0; | ||
// void async function() { | ||
// try { | ||
// var t1 = new Promise((resolve, reject) => { | ||
// setTimeout(() => { | ||
// resolve(2000); | ||
// }, 2000); | ||
// }); | ||
// var t2 = new Promise((resolve, reject) => { | ||
// setTimeout(() => { | ||
// resolve(1000); | ||
// }, 1000); | ||
// }); | ||
// // { t1: 2000, t2: 1000 } | ||
// console.log(await promise_mtd.all({ t1, t2 })); | ||
// // as Promise.all | ||
// // [ 2000, 1000 ] | ||
// console.log(await promise_mtd.all([ t1, t2 ])); | ||
// } catch (err) { | ||
// console.log('Raise', err); | ||
// } | ||
// }(); |
{ | ||
"name": "promise_mtd", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Set of methods allowing simplify work with Promises in cycle. Methods: forEach, map, while, transform, parallel", | ||
@@ -60,3 +60,4 @@ "main": "index.js", | ||
"thunk", | ||
"combinator" | ||
"combinator", | ||
"promise all" | ||
], | ||
@@ -63,0 +64,0 @@ "author": "dm-kamaev@rambler.ru", |
# promise_mtd | ||
Set of methods allowing to simplify work with promises in cycle. | ||
Implementation of ```forEach``` and ```map``` for working with array data when it's needed to apply asynchronous function to each element. | ||
Method ```transform``` allows to iterate asynchronously over an array similarly to ```map```, but also it can skip unnecessary data. | ||
Implementation of cycle ```while``` for using with promise. | ||
Method ```parallel``` allows to run concurrently promises similarly to method ```Promise.all```, but with limit. | ||
* Implementation of ```forEach``` and ```map``` for working with array data when it's needed to apply asynchronous function to each element. | ||
* Method ```transform``` allows to iterate asynchronously over an array similarly to ```map```, but also it can skip unnecessary data. | ||
* Implementation of cycle ```while``` for using with promise. | ||
* Method ```parallel``` allows to run concurrently promises similarly to method ```Promise.all```, but with limit. | ||
* Method ```all``` allows to run concurrently promises similarly to method ```Promise.all```, but supports receipt of parameter such as object ```{ k1: Promise, k2: Promise }``` not only as array. | ||
The library has no dependencies 😀. | ||
@@ -18,2 +21,3 @@ | ||
const promiseMtd = require('promise_mtd'); | ||
void async function () { | ||
@@ -36,2 +40,3 @@ await promiseMtd.forEach([ 300, 200, 100], async function (el, i) { | ||
const promiseMtd = require('promise_mtd'); | ||
void async function () { | ||
@@ -54,2 +59,3 @@ let res = await promiseMtd.map([ 300, 200, 100], async function (el, i) { | ||
const promiseMtd = require('promise_mtd'); | ||
void async function() { | ||
@@ -75,2 +81,3 @@ try { | ||
### transform(Array<any>, Function(el, index)) | ||
@@ -80,2 +87,3 @@ Iterating over an array and filter over promises | ||
const promiseMtd = require('promise_mtd'); | ||
void async function() { | ||
@@ -94,2 +102,3 @@ let res = await promiseMtd.transform([ 1, 2, 3, 4 ], function (el, i) { | ||
### while(condition: Function(): Boolean, Function) | ||
@@ -99,2 +108,3 @@ ```While``` over promises serially | ||
const promiseMtd = require('promise_mtd'); | ||
void async function() { | ||
@@ -108,2 +118,35 @@ let i = 0; | ||
}(); | ||
``` | ||
### all(condition: Function(): Boolean, Function) | ||
```All``` over promises serially | ||
```js | ||
const promiseMtd = require('promise_mtd'); | ||
void async function() { | ||
try { | ||
var t1 = new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve(2000); | ||
}, 2000); | ||
}); | ||
var t2 = new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve(1000); | ||
}, 1000); | ||
}); | ||
// { t1: 2000, t2: 1000 } | ||
console.log(await promise_mtd.all({ t1, t2 })); | ||
// as Promise.all | ||
// [ 2000, 1000 ] | ||
console.log(await promise_mtd.all([ t1, t2 ])); | ||
} catch (err) { | ||
console.log('Raise', err); | ||
} | ||
}(); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11362
10
237
144