Skip to content

lakca/async-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published