Menu

Post image 1
Post image 2
1 / 2
0

Promises: Then's Second Argument

DEV Community·Samuel Rouse·19 days ago
#uCoQcMP0
Reading 0:00
15s threshold

You may already know that .then() accepts two arguments : then ( onFulfilled , onRejected ) Enter fullscreen mode Exit fullscreen mode If either argument is omitted or not a function, it is replaced with an identity or, for rejection, a "thrower". // Conceptually what `.then()` does with no arguments . then (( x ) => x , ( x ) => { throw x ; }) Enter fullscreen mode Exit fullscreen mode The second argument alone is not only equivalent to .catch() , catch is just a wrapper around .then(undefined, onRejected) . But there's an interesting difference when you specify two: then's second argument is parallel . Not that is operates at the same time, but it creates a different and separate path through the chain. The two arguments are isolated from each other. Consider this: // Divergent paths through the code getUserSettings () . then ( transformSettings , loadDefaults ) . then ( showSettingsPage ) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More