June 2018
Beginner
288 pages
6h 31m
English
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.