News for hackers. Stuff that matters.
Re:What's so great about JavaScript Promises? by rektide on Tuesday January 29, 2013 @02:11PM (#5135646)
Promises make a handy wrapper for any kind of value-in-the-future, be that the mundane case of invoking non-blocking functions with callbacks, in the case of getting values from remote remote systems (https://github.com/kriskowal/q-connection), and, I dare say, if we had coroutines, they'd make a great first-class object for pulling result values out of them too.

A promise is agnostic to your concern. Thanks for writing.

Re:What's so great about JavaScript Promises? by munificent on Tuesday January 29, 2013 @06:43PM (#5137162)
If you have coroutines, I don't think promises/futures are worth much. You don't need a value that represents "something I don't have yet" because an API can just block the current coroutine until it has the value.

There may be some utility in being able to pass them around so that the code that calls the API isn't the place where the block occurs, but I'm not convinced it's worth the extra complexity and API fragmentation to care about that.

Re:What's so great about JavaScript Promises? by bad_user on Wednesday January 30, 2013 @04:26AM (#5138724)
Consider this piece of code:

    val resultA = something()
    val resultB = somethingElse()

    return resultA + resultB
With Futures, the processing for resultA and resultB would be done in parallel, because the call to something() does not block. To combine them you don't even need to wait for the processing to finish, because you just create another Future.

Also, being able to pass them around is a really important use-case and Futures are also all about error handling. With Scala it's really trivial to wrap the async support in Servlets 3.0 and make your controllers return Future responses. Then in the servlet you just attach onComplete and onFailure events to return the request when it's ready or when it fails. Works like a charm.

The greatest thing about Futures is that the concept is entirely agnostic to the underlying implementation details. You could have a Future result that's being processed asynchronously by an IO loop (e.g. ning's AsyncHttpClient), you could have a Future result that's being processed by a thread and you can combine the results.

If anything, I don't think you worked with Futures much. You should try it out in Scala, where Futures (from Akka or Scala 2.10) are modelled as monadic types, making them highly composable. Doing multi-threading with Futures in Scala is like working with Lego blocks.

Re:What's so great about JavaScript Promises? by jrochkind1 on Tuesday January 29, 2013 @06:57PM (#5137219)
I'm curious what language you have used coroutines in where it works out that way.

In my experience of using fibers in ruby (which I _think_ are substantially/exactly the same as coroutines?), it hasn't been like you describe at all -- promises, or something other higher level abstraction, are still pretty neccesary to do useful and comprehensible things with them. So my experience colors my understanding and I think "What's he talking about, that doesn't make any sense."

More likely, you have experience in a language where things are done differently enough that it all comes out different.

What language?

Re:What's so great about JavaScript Promises? by rarrrrrr on Tuesday January 29, 2013 @09:00PM (#5137647)
Python w/ Gevent, Go, and Erlang have this.
Re:What's so great about JavaScript Promises? by bad_user on Wednesday January 30, 2013 @04:30AM (#5138731)
I haven't worked with neither Go or Erlang, but it would have been nice if you could use some kind of Future/Promises framework with Python's Gevent.
Re:What's so great about JavaScript Promises? by xt on Tuesday January 29, 2013 @09:22PM (#5137692)
Lua.