Promises
Callbacks are good, they solve our problem of writing asynchronous code. But, as you may have noticed in the preceding code examples, callbacks are very verbose and have one too many handshakes. Additionally, if you want to write multiple callbacks wherein the response of one async operation triggers another async operation, we would have a very complex looking code with callbacks chaining to other callbacks.
To solve these problems we have promises. The promises are now part of native JavaScript since ES2015, so if we write a TypeScript code with promises, we would want to set our target compilation to ES2015 in tsConfig.json.
So, what are promises? A promise is an object which is returned by the asynchronous call and which represents ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access