1.0.1 • Published 3 years ago

@lakca/async-flow v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.
})
1.0.1

3 years ago

1.0.0

3 years ago