News for hackers. Stuff that matters.
Re:Fixing the callback spaghetti in node.js by diamondhead on Thursday September 29, 2011 @04:44AM (#3051644)
JavaScript itself gives developers enough power to beautify messy async code, already. Below is the rewrite of the first example in that page, with async function composition:

====

/* https://gist.github.com/1250314 */

var db = require('somedatabaseprovider'),

      compose = require('functools').compose;
compose.async(getApp, connect, select)({ url:'/price', host:'host', pass:'123' }, function(error, shift){

  shift.conn.close();

  shift.res.send(shift.products[0]);
});

====

It's that easy to abstract those messy callbacks using some functional tools.

There are no comments on this comment yet.