javascript - Async/await not working -


i'm trying number 1 console.log first it's not. doing wrong?

thank you.

let timer = function(time, message) {     settimeout((time) => {         console.log(`alert: ${message}`);     }, time);   //return time; }  const asyncdemo = async function asyncdemo(time, message) {     try {         var time1 = await timer(3000, "number 1");     } catch (e) {         console.log("critical error!");     }     try {         var time2 = await timer(1000, "number 2");     } catch (e) {         console.log("critical error!");     } }  asyncdemo(); 

ansync/await depends on promises work. function needs return promise. instance:

let timer = function(time, message) {     return new promise((resolve, reject) =>{             settimeout((time) => {                 console.log(`alert: ${message}`);                 resolve()             }, time);      })  } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -