# async-cycle **Repository Path**: sgout/async-cycle ## Basic Information - **Project Name**: async-cycle - **Description**: This is an asynchronous loop of the serializer. Provide two methods: asyncWhile/asyncMap, the former can end the loop early and the latter cannot。 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2020-05-12 - **Last Updated**: 2021-06-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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 ```js const { asyncMap, asyncWhile } = require ('async-cycle'); const keywords = [ 'Colin Han', 'Shealtiel Li' ]; const createPromise = async (value) => { return new Promise(r => { r(value); }); }; (async () => { await asyncWhile(keywords,async value => { return createPromise(value); }); //['Colin Han'] await asyncMap(keywords,async value => { return createPromise(value) ; }); //['Colin Han','Shealtiel Li'] })(); ``` ## API ### asyncWhile(input, mapper) #### input Type: `Iterable` Mapped over serially in the `mapper` function. Type: `Array、Object` Receive return value Receive return value ### asyncMap(input, mapper) Same as above