zzzgit / kaze

asynchronous control flow lib implemented in a promise way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

code style: prettier

kaze

asynchronous flow control lib implemented in a promise way

install

npm i kaze

terminology

AsyncFunc

A function which return a promise.

assertFunc

A specilal AsyncFunc of which the promise will be resolved with a boolean value.

badges

API

waterfall

This function takes an array of AsyncFuncs and excute them in series. Each function pass their results to the next in the array. If any of the functions is rejected, the following functions won't be executed, and the main promise will be immediately rejected as well.

example:

const counter = accumulator => Promise.resolve(accumulator + 1)
let promise = waterfall([counter, counter], 1)
promise.then(data => console.log(data)) // 3

compose

This is similar to waterfall, but it create a function which is a composition of the passed AsyncFuncs. Composing functions f(), g(), and h() would produce the result of f(g(h())). Each function consumes the return value of the function that follows.

example:

const counter = accumulator => Promise.resolve(accumulator + 1)
let newFunc = compose([counter, counter])
console.log(newFunc(1)) // 3

whilst

It excute iteratee repeately, while test returns true. The return promise will be resolved right after the loop end.

example:

const test = () => Promise.resolve()
const counter = accumulator => Promise.resolve(accumulator + 1)
let newFunc = compose([counter, counter])
console.log(newFunc(1)) // 3

About

asynchronous control flow lib implemented in a promise way

License:GNU Lesser General Public License v3.0


Languages

Language:TypeScript 84.0%Language:JavaScript 15.7%Language:Shell 0.3%