Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Simple Atomic Task Definition

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


This is a simple task execution helper that is heavily influenced from jake and grunt. It's kind of like jake but without the build goodies, and designed to work in the browser as well as node.

Build Status

Example Usage

Define a task a:

taskify('a', function() {

Then define another task that relies on task a:

taskify('b', ['a'], function() {

Run task b:'b');

Which would generate the following output:


Asynchronous Behaviour

Specifying that a task handler behaves asynchronously is very similar to the way you would do this in a grunt task:

taskify('c', function() {
    // call the async method of the task (passed to the runner as this)
    var done = this.async(); 

    // when the task has been completed call done
    // the first argument is reserved for an error (if one occured)
    // and subsequent arguments will be placed on the context.results object
    setTimeout(function() {
    }, 1000);

Or a slightly less contrived example:

taskify('load-data', function() {
    fs.readFile(path.resolve('data.txt'), 'utf8', this.async()); 

Capturing Result Data

When you call the function, Taskify creates a new ExecutionContext for the task dependency tree that will be executed. This execution context is not persistent though and only lasts until the requested tasks have completed their execution (or you capture the reference).

To capture the results of a task execution you will need to handle the complete event for a particular task. Let's look at the simple example of our load-data task from before:'load-data').on('complete', function(err) {
    if (err) return;

    console.log('loaded data: '  + this.context.results['load-data']); 

Additionally, because Taskify uses eve under the hood for eventing, you can implement eve handlers to capture the complete events also:

eve.on('task.complete.load-data', function(err) {
    if (err) return;

    console.log('loaded data: '  + this.context.results['load-data']); 

NOTE: The eve namespace for events is task. rather than taskify. as usually I find mapping to task requires a little less typing. Additionally, I usually do something like var task = require('taskify');...

Experimental Use Case: Handling HTTP Requests without Middleware

While this was not one of the reasons I created Taskify, it is something I experimented with as a way of resolving preconditions for a particular route handler. While most web frameworks implement middleware to handle things like cookie or body parsing Taskify can offer an alternative approach.

For instance, consider the following example implementing using Tako and cookies:

var tako = require('tako'),
    task = require('taskify'),
    Cookies = require('cookies')
    app = tako();

// define a task to extract cookies and place on the context
task('auth', function(req, res) {
    this.context.cookies = new Cookies(req, res);    

// define a
Something went wrong with that request. Please try again.