I
I
IvanIvanIvanIvanIvan2018-08-04 22:49:38
JavaScript
IvanIvanIvanIvanIvan, 2018-08-04 22:49:38

Why doesn't it wait for the first function to execute?

Why is the second console.log executed first. If we have awiat hanging on the first console.log('one')?

module.exports = app => {
    app.post('/api/emailVerified', async (req, res) => {
      const { uid } = req.body;
      try {
        await setTimeout(async () => {
          return console.log('One');
        }, 2000);
        console.log('two');
        } catch(e){
          console.log(e);
        }
    });
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2018-08-04
@IvanIvanIvanIvanIvan

await works with RTFM promises
https://developer.mozilla.org/uk/docs/Web/JavaScri...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question