software master at the intersection of technology, science and art



observables, promises, subjects

These are implementations of the ajax calls in javascript. They are implemented in the Angular RxJS library, each implementing a form of observer/observable design. The Promise and the Observable implement the observable pattern and Subject implments the observer and observable patterns. Ajax is pivotal for web applications to retrieve data and then process it on the client. Usually in an ajax call, a http request is made and when the httpresponse is receive a callback method is invoked. The RxJs library enables the processing of a single item or mutliple items.

In discussion os of the Observer pattern, the observable is called a Subject - this can be confusing. Here the Obeservable is the SUbject and Subject is a combination of observer and observable. Major differences between the Promise and Observable are:

Promise is eager - the callback function provided to the constructor is fired immediately.
Observbable is lazy - the callback function is not fired until the observable is subscribed to.
Promise is always asynchronous.
Observable may be asynchronous or synchronous
Promise emits a single value
Observable can emit multiple values
Observables streams can be manipulated by RxJs operators.