queue
!Build statustravis-imagetravis-url
!Git taggit-imagegit-url
!NPM versionnpm-imagenpm-url
!Code stylestandard-imagestandard-urlSimple function queue
Installation
$ npm install @f/queue
Usage
var createQueue = require('@f/queue')
var queue = createQueue()
queue.push(function () {
console.log('hello world')
})
queue.flush()
Or in ES6:
import createQueue from '@f/queue'
const {add, flush} = createQueue()
add(() => console.log('hello world'))
setTimeout(flush)
API
queue()
Returns: An object containing two functions,add
and flush
:add(fn)
- Add fn
to the queue.
flush()
- Flush the queue - i.e., run all the fns
, clear the queue, and return an array of their return values.Note that queue does not use a prototype, so you can call
flush
and add
without invoking them on the queue object.