I'm newbie in NodeJs. This is my code for learning asynchronous function.
//--------------------- MAIN ---------------
console.log("Endpoint 1\r\n");
testThread(1000000000,function (result){
console.log(">>>>"+result+"\r\n");
});
console.log("Endpoint 2\r\n");
//------------------------------------------
function testThread(data,callback) {
//take a long time
for(j=0;j<data;j++) {
a = 122342342342424242431*3543652636364;
}
//
callback(a);
}
Run it:
node testthread.js
Always the result is:
Endpoint 1
>>>>4.335387639806787e+32
Endpoint 2
System prints "Endpoint 1", take 2 seconds, it prints ">>>>4.335387639806787e+32" after then it prints "Endpoint 2"
I'm not found the asynchronous here. It should be:
Endpoint 1
Endpoint 2
>>>>4.335387639806787e+32
Please explain me.