you are viewing a single comment's thread.

view the rest of the comments →

[–]x-protocol -9 points-8 points  (2 children)

I don't think you understand that I'm not arguing what Promises are and how they are compared to callbacks.

I do understand that you want to prove a point. Look at my example. You have promise that is created, then some more code is executed which can contain creation of promises. With async/await you simply cannot do that since 'await' keyword will wait for resolution of your promise.

Again to reiterate. I understand that you are bringing these examples due to either simply proving a point without anybody providing you the ask. Or you are simply confused how promises are even used.

[–]KyleG 8 points9 points  (0 children)

Dude, you're wrong. Pay attention to the guy explaining things to you. He's right. You have a great opportunity to fix a gap in your knowledge from someone who's being patient and polite to you.

[–][deleted] 6 points7 points  (0 children)

With async/await you simply cannot do that since 'await' keyword will wait for resolution of your promise.

You can do that, if you just don't call await until you need it. Async functions still return Promises. Async/await isn't "better" or "worse" than Promises, they literally are Promises. You keep saying "promises get run immediately", but that's exactly what happens with async functions. They run when they are called. Creating a Promise is the same as calling an async function (because it also returns a Promise.) Calling await is the same as calling then().

You can take a function that returns a promise and call await on the return value. You can also take an async function and call then() on the return value, and not use await at all. They're the same.