@promises/for-each-parallel
v0.5.0
Published
For Each Parallel is package from Promises library
Downloads
27
Maintainers
Readme
@promises/for-each-parallel
For Each Parallel is package from Promises library
Use
Module
$ npm install --save @promises/for-each-parallel
import {
default as forEachParallel
} from '@promises/for-each-parallel';
Browser
<script src="https://unpkg.com/@promises/for-each-parallel/bundle.umd.min.js"></script>
let {
forEachParallel
} = P;
Examples
let array: number[] = [3, 7, 1, 5];
console.log('before');
forEachParallel(array, (value: number) => {
console.log(`start: ${ value }`);
return timeout((resolve) => {
console.log(`end: ${ value }`);
resolve();
}, value);
}).then(() => {
console.log('complete');
});
console.log('after');
// => before
// => after
// => start 3
// => start 7
// => start 1
// => start 5
// => end 1
// => end 3
// => end 5
// => end 7
// => complete
Functional programming
Module
$ npm install --save @promises/for-each-parallel
import {
__,
default as forEachParallel
} from '@promises/for-each-parallel/fp';
Browser
<script src="https://unpkg.com/@promises/for-each-parallel/fp/bundle.umd.min.js"></script>
let {
__,
forEachParallel
} = PF;
Examples
let array: number[] = [3, 7, 1, 5];
console.log('before');
forEachParallel((value: number) => {
console.log(`start: ${ value }`);
return timeout((resolve) => {
console.log(`end: ${ value }`);
resolve();
}, value);
})(Infinity, array).then(() => {
console.log('complete');
});
console.log('after');
// => before
// => after
// => start 3
// => start 7
// => start 1
// => start 5
// => end 1
// => end 3
// => end 5
// => end 7
// => complete
Wrapper
Module
$ npm install --save @promises/for-each-parallel
import Promises from '@promises/core';
import '@promises/for-each-parallel/add';
Or
import Promises from '@promises/for-each-parallel/add';
Browser
<script src="https://unpkg.com/@promises/core/bundle.umd.min.js"></script>
<script src="https://unpkg.com/@promises/for-each-parallel/add/bundle.umd.min.js"></script>
let {
Promises
} = P;
Examples
let array: number[] = [3, 7, 1, 5];
let promises: Promises<number[]> = Promises.resolve<number[]>(array);
console.log('before');
promises.forEachParallel((value: number) => {
console.log(`start: ${ value }`);
return timeout((resolve) => {
console.log(`end: ${ value }`);
resolve();
}, value);
}).then(() => {
console.log('complete');
});
console.log('after');
// => before
// => after
// => start 3
// => start 7
// => start 1
// => start 5
// => end 1
// => end 3
// => end 5
// => end 7
// => complete
Compatibility
These modules are written in typescript and available in ES5 and ES6 standard, the requirements are a global Promise (native or polyfill).
License
Copyright © 2017 Yisrael Eliav, Licensed under the MIT license.