promise_mtd
Advanced tools
Comparing version 1.0.4 to 2.0.4
@@ -13,3 +13,3 @@ 'use strict'; | ||
promise_mtd.while = require('./promise_mtd/while.js'); | ||
promise_mtd.async_while = promise_mtd.asyncWhile = require('./promise_mtd/async_while.js'); | ||
@@ -16,0 +16,0 @@ promise_mtd.parallel = require('./promise_mtd/parallel.js'); |
{ | ||
"name": "promise_mtd", | ||
"version": "1.0.4", | ||
"version": "2.0.4", | ||
"description": "Set of methods allowing simplify work with Promises in cycle. Methods: forEach, map, while, transform, parallel", | ||
@@ -9,2 +9,3 @@ "main": "index.js", | ||
}, | ||
"types": "./index.d.ts", | ||
"keywords": [ | ||
@@ -11,0 +12,0 @@ "promise", |
@@ -6,3 +6,3 @@ # promise_mtd | ||
* 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. | ||
* Implementation of cycle while as ```asyncWhile```(while is reserved word) for using with promise. | ||
* Method ```parallel``` allows to run concurrently promises similarly to method ```Promise.all```, but with limit. | ||
@@ -64,3 +64,3 @@ * 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. | ||
resolve(Boolean(i)); | ||
}, time*1000); | ||
}, time * 1000); | ||
}); | ||
@@ -78,17 +78,10 @@ }); | ||
void async function() { | ||
try { | ||
await promiseMtd.parallel([ 3000, 3000, 3000, 2000, 2000, 2000, 1000], 3, async function(t, i) { | ||
return new Promise((resolve) => { | ||
// if (i === 4) { | ||
// throw new Error('stop'); | ||
// } | ||
setTimeout(() => { | ||
console.log(t); | ||
resolve(); | ||
}, t); | ||
}); | ||
await promiseMtd.parallel([ 3000, 3000, 3000, 2000, 2000, 2000, 1000], 3, async function(el, i) { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
console.log(el); | ||
resolve(); | ||
}, t); | ||
}); | ||
} catch (err) { | ||
console.log('Raise', err); | ||
} | ||
}); | ||
}(); | ||
@@ -118,3 +111,3 @@ ``` | ||
### while(condition: Function(): Boolean, Function) | ||
### whileTrue(condition: Function(): Boolean, Function) | ||
```While``` over promises serially | ||
@@ -126,3 +119,3 @@ ```js | ||
let i = 0; | ||
await promiseMtd.while(() => i < 5, async function () { | ||
await promiseMtd.asyncWhile(() => i < 5, async function () { | ||
console.log(i); | ||
@@ -142,26 +135,22 @@ i++; | ||
void async function() { | ||
try { | ||
var t1 = new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve(2000); | ||
}, 2000); | ||
}); | ||
var t1 = new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve(2000); | ||
}, 2000); | ||
}); | ||
var t2 = new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve(1000); | ||
}, 1000); | ||
}); | ||
var t2 = new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
resolve(1000); | ||
}, 1000); | ||
}); | ||
// { t1: 2000, t2: 1000 } | ||
console.log(await promiseMtd.all({ t1, t2 })); | ||
// { t1: 2000, t2: 1000 } | ||
console.log(await promiseMtd.all({ t1, t2 })); | ||
// as Promise.all | ||
// [ 2000, 1000 ] | ||
console.log(await promiseMtd.all([ t1, t2 ])); | ||
} catch (err) { | ||
console.log('Raise', err); | ||
} | ||
// as Promise.all | ||
// [ 2000, 1000 ] | ||
console.log(await promiseMtd.all([ t1, t2 ])); | ||
}(); | ||
``` |
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
14058
12
288
150