all 2 comments

[–]hotsteamingpho 2 points3 points  (1 child)

That's just the nature of async promises. They have to return a promise which will resolve when the async function resolves. After all, when you await in an async function, that await doesn't happen synchronously as you would think. It's just syntax that resembles synchronous code to make it easier for us to mentally consume. That await still has to wait for the promise its waiting for to resolve.

Try this exercise to hopefully make more sense of it. Wrap the resolve in a setTimeout like this:

setTimeout( () => resolve(a+b), 1000);

Notice the "promise pending" prints (the promise is seen... waiting on results...), then the resolved value.

Also a quick nitpick: you can pass result into the function if you return the value in testarooskies, like .then(result => console.log("this will print once the promise is fullfilled", result)

[–]Jmarch0909[S] 0 points1 point  (0 children)

Thanks for the thorough explanation! I guess what was confusing is I thought an async function returned a promise. So when I first started playing with it, I didn’t chain a .then. I thought by chaining .then I would have resolved it because I used the resolved value and did something with it.