Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm currently working on porting dojo.Deferreds to node.js. On top of them I am also working on some API sugar that makes it really easy to aggregate the results of multiple deferreds:

    (group)
      ('a', db.query('SELECT A ...'))
      ('b', db.query('SELECT B ...'))
      ('c', db.query('SELECT C ...'))
      .addCallback(function(results) {
        p(results) // {a: ..., b: ..., c: ...}
      });
This will make it very easy to run multiple things in parallel, yet handle all of them in one callback.

Check http://github.com/felixge/node-deferred for more info.

Do not use wait() too much, it will be memory expensive.



Deferred[1] is originally used in Python's Twisted framework. It's also used in Bob Ippolito's MochiKit's library. Generally, it's a great abstraction and I am looking forward to see your results. As I recall Twisted has an ability to chain deferrers.

[1] http://twistedmatrix.com/documents/current/core/howto/defer....


The whole point is that they innately bind to one another -- they are, after all, monadic (gasp!)


It's very easy to define bind and return for event driven code, so most event driven programming is or can become monadic.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: