I'm trying to understand some basic stuff about async function in JS.
I have this code:
start()
Start()
is defined as follow:
async start(){
my_function("function 1").then(() => {
// Do something
})
my_function("function 2").then(() => {
// Do something
})
}
And then my_function(string)
is defined as:
async my_function(string){
let while_id = 1
while(true){
console.log("[" + string + "] " + while_id)
} // while
}
So, being asynchronous functions I expect to see in the terminal a mix of strings belonging to function 1 and function 2. But in reality is printed only the while of function 1. Am I missing something?
Edit 1
You guys are telling me that while
loop is not async. So what can be a solution in order to have the result I expect?