getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
178.28k stars 33.43k forks source link

Concurrent Iterations aync map utility snippet note says "you can't signal async rejection", but its wrong #1680

Closed OahMada closed 4 years ago

OahMada commented 4 years ago

Yes, I promise I've read the Contributions Guidelines (please feel free to remove this line).


Please type "I already searched for this issue": I already searched for this issue Edition: (1st or 2nd) 1st Book Title: Async & Performance Chapter: Promises Section Title: Concurrent Iterations Problem: The code snippet note says "you can't signal async rejection", but it's wrong. A simple illustration below

var p1 = Promise.resolve( 21 );
var p2 = Promise.resolve( 42 );
var p3 = Promise.reject( "Oops" );

// double values in list even if they're in
// Promises
Promise.map( [p1,p2,p3], function(pr,done){
    // make sure the item itself is a Promise
    done(pr);
} )
.then( function(vals){
    console.log( vals );    //never get here
}, function(err){
    console.log(err);  // Oops
} );
getify commented 4 years ago

OK. But the book is 5 years old.