1.2.0 • Published 4 years ago

async-cycle v1.2.0

Weekly downloads
41
License
MIT
Repository
github
Last release
4 years ago

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

1.2.0

4 years ago

1.1.0

4 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago