@lakca/async-flow

1.0.1 • Public • Published

async-flow

Call functions in different synchronous flow(tick/phase).

Usage

// preparation codes

let count = 0
function log() {
    return console.log.bind(console, ++count)
}
const asyncFlow = require('@lakca/async-flow')
const { Flows } = asyncFlow

(default) asyncFor = setTimeout

asyncFlow(log)(log)(log)

log()

setTimeout(log)
// output: 1, 4, 2, 5, 3

asyncFor = process.nextTick

asyncFlow(log, process.nextTick)(log)(log)

log()

asyncFor(log)
// output: 1, 4, 2, 5, 3

Alternative

const flows = new Flows()
flows.push(log)
flows.push(log)
flows.push(log)
log()
setTimeout(log)
// output: 1, 4, 2, 5, 3

Example

asyncFlow(() => {
    // create and place element in a flex flow.
})(() => {
    // * rendering dom has been executed at the between.
    // calculate the element layout and do related things.
})

Package Sidebar

Install

npm i @lakca/async-flow

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

5.38 kB

Total Files

4

Last publish

Collaborators

  • lakcaorg