Node Roundup: 0.6.6, asyncblock, Introduction to Node Modules, Review19

2011-12-21 16:00

Node Roundup: 0.6.6, asyncblock, Introduction to Node Modules, Review19

by

at 2011-12-21 08:00:00

original http://feedproxy.google.com/~r/dailyjs/~3/f9uQWc0uPY8/node-roundup

Node 0.6.6

Node 0.6.6 is out, which updates npm, fixes some bugs, and adds pause/resume semantics to stdin. Node also has a new website that is greener than ever, but remains clean and features a new corporate-friendly edge.

There’s also a post on the official Node blog entitled Growing up by Ryan Dahl that discusses Windows Azure support:

The overarching goal of the port was to expand our user base to the largest number of developers. Happily, this has paid off in the form of being a first class citizen on Azure.

asyncblock

asyncblock (License: MIT, npm: asyncblock) is a fork of node-green-light. It works like a flow control library combined with node-fibers.

The author compares a ‘pure Node’ example with his own library’s code:

function example(callback){
    var finishedCount = 0;
    var fileContents = [];

    var continuation = function(){
        if(finishedCount < 2){
            return;
        }

        fs.writeFile('path3', fileContents[0], function(err) {
            if(err) {
                throw new Error(err);
            }

            fs.readFile('path3', 'utf8', function(err, data){ 
                console.log(data);
                console.log('all done');
            });
        });
    };

    fs.readFile('path1', 'utf8', function(err, data) {
        if(err) {
            throw new Error(err);
        }

        fnishedCount++;
        fileContents[0] = data;

        continuation();
    });

    fs.readFile('path2', 'utf8', function(err, data) {
        if(err) {
            throw new Error(err);
        }

        fnishedCount++;
        fileContents[1] = data;

        continuation();
    });
}

This is the equivalent source using asyncblock and fibers:

var asyncblock = require('asyncblock');

asyncblock(function(flow){
    fs.readFile('path1', 'utf8', flow.add('first'));
    fs.readFile('path2', 'utf8', flow.add('second'));

    var fileContents = flow.wait();

    fs.writeFile('path3', fileContents.first, flow.add());
    flow.wait();

    fs.readFile('path3', 'utf8', flow.add());
    var data = flow.wait();

    console.log(data);
    console.log('all done');
});

Error handling is addressed by including flow.errorCallback. There are examples of how to use this in the project’s documentation.

Introduction to Node Modules

Robert Kuzelj has been writing a series of posts about Node modules:

He demonstrates how to make packages, and how to take advantage of npm’s major features.

Review19

In other Node-related DailyJS articles I’ve invited readers to share their own apps with the community. Review19 by Srirangan is one such project: a kanban and scrum project management tool.

It’s built with Socket.IO to provide a real-time view of a project, and uses simple agile-inspired records that should be familiar to users of Jira or Pivotal Tracker.

Sign up is free, so give it a try. The author has a Google Group to support the community at Review19 Community.