Skip to Main Content
Rediscovering JavaScript
book

Rediscovering JavaScript

by Venkat Subramaniam
June 2018
Beginner content levelBeginner
288 pages
6h 31m
English
Pragmatic Bookshelf
Content preview from Rediscovering JavaScript

Chaining Promises

One elegant feature of promises is that they form a pipeline like in the functional composition we saw in Arrow Functions and Functional Style. Since both then() and catch() return a promise, calls to these functions may be chained to apply a series of filtering and transformations. An example will help you appreciate this elegance.

In the example in No Thanks to Callback Hell we used the fs library’s readFile() asynchronous method that relied on callback. The fs-extra library provides a wrapper around the functions of the fs library. We will use that to read the contents of a file asynchronously, but this time using promises instead of callbacks.

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.
Start your free trial

You might also like

Object-Oriented JavaScript - Third Edition

Object-Oriented JavaScript - Third Edition

Stoyan STEFANOV, Ved Antani
Deno Web Development

Deno Web Development

Alexandre Portela dos Santos

Publisher Resources

ISBN: 9781680506174Errata Page