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

Promises hep deal with asynchronous functions by providing a convenient way to pass success/fail methods in a way some people prefer more than classic callbacks.

Streams are a totally different use case. Streams are used when you want to process data one part at a time without having to have all of the data in memory at once.

*edit: typo



Promises are actually about trust, not syntax. With a callback you have to trust that the function that will invoke your callback (which might not be something you wrote) will only ever call it once, that it will pass through errors, that it won't call both your success and failure callbacks, etc.

With a promise (or rather, following the promise specification) you instead get back an object that you choose how to handle. That object is either pending or else an immutable success or failure result. Either success or failure will be called (not both), and whichever result is called can only be called once. As such, promises allow you to avoid inversion of control and to safely interact with potentially untrusted code.

This great series of articles helped me understand this: http://blog.getify.com/promises-part-2/




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

Search: