taniarascia / comments

Comments
7 stars 0 forks source link

asynchronous-javascript-event-loop-callbacks-promises-async-await/ #46

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Understanding the Event Loop, Callbacks, Promises, and Async/Await in JavaScript | Tania Rascia

This article was originally written for DigitalOcean. Introduction In the early days of the internet, websites often consisted of static…

https://www.taniarascia.com/asynchronous-javascript-event-loop-callbacks-promises-async-await/

markomeje commented 4 years ago

Very explanatory. Thank you and keep it up.

ephraimduncan commented 4 years ago

Thank You.

kemalgencay commented 4 years ago

Wonderful article, thank you,

mshams999 commented 4 years ago

Nice

LissetteIbnz commented 4 years ago

Great!

VikR0001 commented 4 years ago

I'm reading your article and learning a lot! I have a quick question. A lot of my code has this:

            return Promise.resolve()
                .then(() => {
                    let objectFromDatabase = connectors.myTable.findOne({
                        where: {id: objectId}
                    });
                    return objectFromDatabase;
                })
                .catch((err) => {
                    console.log(err);
                });

...this works fine. My question is, do I need to be doing:

         return new Promise.resolve()

....instead of:

        return Promise.resolve()

And if not, why not if I may ask? Thanks very much in advance for any thoughts / info!

philsav commented 4 years ago

Very good article, just need to know is which scenario to use promise and which to use async/await, Is promises used when multiple promises need to be checked using promise all, is there also a await all

astrit commented 4 years ago

What a detailed explanation, learned a-lot from it. thank you

KVNEZE commented 4 years ago

This is a really well written article, I connected dots that I didn't know I needed to connect.

Thank you.

andrebonfimdev commented 4 years ago

Great article. Congratulations!

moofoo commented 4 years ago

Concise and informative.

yonycalsin commented 4 years ago

Nice 👍

pb03 commented 4 years ago

Nicely explained. Maybe little more explicit here in the Queue section:

but that it will add the anonymous function to the queue in that amount of time.

Web API will add this function to the queue (not directly from the stack)

DrWongKC commented 4 years ago

Thank you so much for writing this. You're an incredibly teacher. :) I hope you keep writing about programming, even after you decide to retire. It's really helping me.

liwei766 commented 4 years ago

Good personal blog! Static site and commenting system works.

kusaljay commented 3 years ago

Thanks for this article. Can you please write a one for Closures?

sddania commented 3 years ago

@VikR0001

My question is, do I need to be doing: return new Promise.resolve() instead of: return Promise.resolve()

as Promise doc says, the resolve method is static and you dont need to instantiate a new Promise to call it.

if you want to use Promise as object you can wrap functions that do not already support promises on Promise constructor:

const promise = new Promise( (res ,rej) => {
    res("hello!")
} )
promise.then(val => console.log(val))

the console will show "hello!"

pedegago commented 3 years ago

Great article. I was reading it for some days in order to understand everything!

hunzaboy commented 3 years ago

Tania, thanks for the great article. I really enjoy your writing style. Simple with full of knowledge.

immaithil commented 2 years ago

It was a great article finally I am able to clear confusion about .then and .catch.

alex-j-garcia commented 2 years ago

Thanks for the great article. Some things didn't make sense right away, but I kept rereading and going through your examples until it clicked!

aakinlalu commented 2 years ago

Thank you

sanfordstaab commented 1 year ago

I'm trying to use a promise or async/await to create a modal dialog API that returns information synchronously but I don't know how to un-stack the promise so that a click event triggers the resolution of the promise except by some kind of setTimeout(forever) hack. I want a simply synchronous api like:


// in the middle of some complex nested operation where callbacks just suck ... const btnText = await msgBox([ 'Yes', 'No', 'Maybe' ], 'Text of messagebox'); if (btnText == 'Maybe') { ....