async-cycle

1.2.0 • Public • Published

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i async-cycle

      Weekly Downloads

      11

      Version

      1.2.0

      License

      MIT

      Unpacked Size

      7.93 kB

      Total Files

      10

      Last publish

      Collaborators

      • shealtiel