Thenables

Something important to know is that a Promise returns straight away, but the result is not available straight away. Promises are also known as thenables, because you need to register a callback with its then() method once the data has been received, like so:

const promise = new Promise((resolve, reject) => {  // either call resolve() if we have a success or reject() if it fails });// the 'promise' variable points to a construct // that will eventually contain a valuepromise((data) => {  // <- registering a callback on then()  // our data has arrived at this point})

In the preceding code, we demonstrated how to create a promise and how to register it with the then() method. The promise variable instance contains a construct that is ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.