queue
Simple 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)
- Addfn
to the queue. -
flush()
- Flush the queue - i.e., run all thefns
, 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.
License
MIT