I
I
Igor2017-08-11 17:22:51
JavaScript
Igor, 2017-08-11 17:22:51

Problem with asycn/await?

Good afternoon.
Tell me what I'm doing wrong:

(async () => {
  let testConnection = async () => {
    await seq.authenticate();
    console.log('Connection ok');
  }
  await testConnection();
})();
console.log('ttt');

Why does the console display first
ttt
, and then
connection ok
? I tried to create my own Promise in it, already call seq.authenticate () and then wrap my Promise in async / await, but I get the same result.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nicholas, 2017-08-11
@hurgadan

Why should it be different in principle?
You did this:

new Promise(function(resolve, reject) {
    seq.authenticate().then(function(result) {
        console.log("Connection ok"); 
        resolve(result);
    });
});
console.log('ttt');

E
emp1re, 2017-08-11
@emp1re

Because console.log is a synchronous method. If that means anything to you :D

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question