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

    and Javascript uses promises and "then ()".
What is "then ()"? Have they created their own wacky fork of Javascript? Javascript already handles asynchronous programming (feel free to argue that is doesn't do it "right" or even "well"), so why extend the language?


It's a method with a signature like this:

    promise.then(callback)
so:

    var p = doSomethingAsync();
    p.then(function () { alert("hello"); })


I'm assuming they only chose to use this pattern for the purpose of keeping function/method signatures as uniform across the languages as possible? I can't see another advantage to this in JS. Seems like all it's doing is wrapping the call to the actual async operation within the 'then' function, and then probably using the callback as the last argument or storing it somewhere where it will be accessible to the async operation right before it returns.


I saw all of those extra spaces around "then" in the article and assumed the worst. Thanks for clearing that up for me!


From what I can tell it's just a convention in their APIs for binding continuations. You do some WinRT asynchronous call and pass a func to the then method to run when it completes. Nothing more than a onFinished event.

No changes to async programming at all, events and continuations as always.




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

Search: