1.2.0 • Published 4 years ago
async-cycle v1.2.0
async-cycle
Map over promises serially
This is an asynchronous loop of the serializer. Provide two methods: asyncWhile/asyncMap, the former can end the loop early and the latter cannot。 这是序列化器的异步循环。提供两种方法:asyncWhile/asyncMap,前者可以提前结束循环,而后者不能。
Install
$ npm install async-cycle
Usage
const { asyncMap, asyncWhile } = require ('async-cycle');
const keywords = [
'Jack',
'Shealtiel Li'
];
const createPromise = async (value) => {
return new Promise(r => {
r(value);
});
};
(async () => {
await asyncWhile(keywords,async value => {
return createPromise(value);
});
//[Jack]
await asyncMap(keywords,async value => {
return createPromise(value) ;
});
//['Jack','Shealtiel Li']
})();
API
asyncWhile(input, mapper)
input
Type: Iterable<unknown>
Mapped over serially in the mapper
function.
Type: Array、Object
Receive return value
Receive return value
asyncMap(input, mapper)
Same as above