Promise Waits To Get Resolve Without Return
Solution 1:
If i understand your question right, you're saying that the first snippet should not work because it's not returning the promises and you're asking why is it working.
Short answer: It's not really working, handlePromise2()
finished and returned without waiting on the promises to get resolved or rejected.
Long answer: It's like you going to the bakery and asking for a bread, but instead of waiting in line after asking for it you leave, the bread still gets baked but then it gets thrown away because the client (In our case that's handlePromise2
) made the call and assumed that the work is finished, after all its scope was to just call that function.
Promises are used so that the client that's calling the function knows to expect something, so after you'd ask for the bread you'd wait for it to be finished, and that's called a promise it's not the actual value (aka bread) but a promise of a value. That's what you're doing in the second snippet.
And now poor handlePromise()
doesn't know what to do with the food
Post a Comment for "Promise Waits To Get Resolve Without Return"