|
|
|
Ask HN: Is JavaScript abandoning Promises
|
|
2 points
by bengg
3251 days ago
|
|
Recently in a technical screening, a senior engineer asked me what I thought about Javascript moving away from Promises in favor of Observables. I replied that I didn't know that Javascript was moving away from Promises, since Promises are part of the ES6 spec. In general, I was blindsided by this. So my 2 questions are: 1. Is Javascript truly moving away from Promises in favor of Observables? 2. Where can I read about the direction that Javascript is taking, so that I can have an educated discussion on the future of Javascript? |
|
Observables are in position to be adopted by ECMAScript in a future spec eventually, but they are still only at Stage 1 of the ES proposal process, and also Observables don't exactly replace Promises so much as extend them.
An Observable can be thought of as a "stream" of promised values rather than just a single promised value. It's a somewhat different paradigm. From the Observable perspective a Promise is a simple Observable that produces a single value and completes immediately after. So you can see Promises are useful in an Observable world as something of a building block.
A good resource on Observables can be: http://reactivex.io/
It's focused on the main cross-platform library for Observables (ReactiveX which has implementations in .NET, Java, JS, more), but a lot of it is applicable to Observables in general and it has a lot of good "marble" diagrams that can help show why Observables can be powerful.
The dry Stage 1 ES spec itself is here: https://github.com/tc39/proposal-observable