News for hackers. Stuff that matters.
Re:By example: Continuation-passing style in JavaScript by tomn on Tuesday November 09, 2010 @01:55PM (#1887485)
Twisted (a python asynchronous network programming framework) does something similar, but inverted. Twisted functions return a Deferred object without blocking. A Deferred is a promise of a value, so rather than passing the callback into the function, you register a callback with the deferred, and the function promises to call it later.

This type of thing has a few nice properties -- you can easily register more than one callback, as well as using them as a pipeline (kind-of like monads in haskell), which are awkward to implement with callbacks.

As an aside, in python you can trick generators into turning synchronous-looking code into asynchronous, which can actually make things look a lot neater if done properly -- i'll provide code if anyone's interested.

Re:By example: Continuation-passing style in JavaScript by viraptor on Tuesday November 09, 2010 @03:58PM (#1887877)
> python you can trick generators into turning synchronous-looking code into asynchronous

Example: http://dieselweb.org/lib/ or https://github.com/saucelabs/monocle

Although Diesel2 is much more interesting, with greenlets support. No more messing about with `yield`, since the blocking functions themselves force a context switch. https://github.com/jamwt/diesel

Re:By example: Continuation-passing style in JavaScript by tomn on Tuesday November 09, 2010 @04:55PM (#1888095)
That looks really interesting, though it seems a bit dangerous -- greenlet feels like a bit of a hack.

I wish I'd found diesel before twisted; it seems a lot more elegant if you don't need any of the built-in protocols. The twisted model is good, there's just too much of it.