0.0.1 • Published 8 years ago

dillydally v0.0.1

Weekly downloads
3
License
GPL-3.0
Repository
github
Last release
8 years ago

dillydally

Install

npm install dillydally

How to use

var queue = require('dillydally');

// Normal function
function foo() { return 'party'; }

// Function returns a promise
function bar() { return Promise.resolve('poop'); }

// Function with arguments
function yarg(a) { return a; }

// Add a function to run in the job queue
queue.addJob(foo).then(console.log) // prints 'party'
queue.addJob(bar).then(console.log) // prints 'poop'
queue.addJob(yarg, 'derp').then(console.log) // prints 'derp'

// waits 500 ms then prints 'party'
queue.addJob(500, foo).then(console.log)

// waits 1000 ms after the previous job then prints 'poop'
queue.addJob(1000, bar).then(console.log)

// prints 'poop' immediately after the previous job
queue.addJob(bar).then(console.log)

// Specify the context for the function to run in
function baz() { return this.test }
queue.addJob({context: {test: 'derp'}}, baz).then(console.log) // prints 'derp'

// Specify context and delay
queue.addJob({delay: 500, context: {test: 'derp'}}, baz).then(console.log) // prints 'derp' after 500ms

// Supply your own Promise lib
queue.Promise = require('bluebird');