Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#10 An important rule | #bonus part #140

Open
mcompote opened this issue Jan 11, 2018 · 0 comments
Open

#10 An important rule | #bonus part #140

mcompote opened this issue Jan 11, 2018 · 0 comments

Comments

@mcompote
Copy link

mcompote commented Jan 11, 2018

Greetings!
I've stumbled upon some thing I can't comprehend.
It is said at the end of lesson's description:

If you are not returning a value from your promise to a caller,
then attach a done handler to guard against uncaught exceptions.

And in #bonus sections:

Try swapping your rejection handler from console.log to alwaysThrows.
Your program will now throw an exception in the global context! Ahh!
Try to fix this using the approach described above.

My code:

function alwaysThrows() { 
    throw new Error("OH NOES");
 }

 function iterate(integer) {  
     console.log(integer);
     return integer+1;
 }

 Promise.resolve( iterate(1) )
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => alwaysThrows() )
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => Promise.resolve( iterate(v) ))
    .then( v => Promise.resolve( iterate(v) ))
    // .catch( e => console.warn(e) )
    .catch( e => alwaysThrows() )
    .done( console.log )

The problem with .done() method of Promise interface. Node refuses to run this code. I looked through MDN articles,etc. but found nothing like .done(). It seems like this method doesn't exist.
Btw, this method exists in Q library...
Could someone please explain what's wrong with my code. Sorry if my question bothers anyone, im just learning.
Thanks in advance

@mcompote mcompote changed the title #11 Multiple promises | #bonus part #10 Multiple promises | #bonus part Jan 11, 2018
@mcompote mcompote changed the title #10 Multiple promises | #bonus part #10 An important rule | #bonus part Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant