Skip to content

Why use this async flow library

shimondoodkin edited this page Nov 10, 2010 · 2 revisions

The problem is that you have to carray the Request and Response, all the way, through the callbcacks and non-callbacks... just to be able to do Response.write() and Response.end() at the end. all the other simple functions dons't need request and response. but even then you must carry it to not loose it at the end.

in a large program you could loose the response variable somewhere, while doing the folowing in every single small or large sync or async function call:

function (error,data,req,res)
{
 (function (error,data,req,ras) 
 {
  (function (error,data,req,res)
  {
   res.end('finally done');
  })(error,data,req,res);
 })(error,data,req,res);
}
// see if you can spot a typo in the code above.

No more complicated closures

  • The shared object simplifies everything with async calls.

Functions can have arguments

  • Now I can use a common library object that contains useful function that can be called asynchronously.
  • It simplified my application structure

With this library I could reinvented the way I use an http server

  • No need to pass req, res as separate arguments, just one simple shared object.
  • I used to store temporary variables of the request in the req object but now i store them in the shared object.