How do we interact with async functions?
E.g:
//javascript
async function test(){
await new Promise(r=>setTimeout(r,200));
return 100
}
global.test=test
//microscript
init = function()
a = test()
end
OUTPUT: a = object end - WHY? and how do we fix this
Don't have much experience with javascript functions, but would you be able to do a callback function that sets the variable to the value?
WOW that should actually working! Will try it
https://microstudio.io/i/Loginus/async/
It's best to handle all asynchronous operations in javascript code.
MicroScript does not support promises.
In the javascript code, after executing the function you need to wait for, save the data to a variable or call a callback function.
I made some sample code for you.
https://microstudio.io/i/Loginus/async/
Oh, another surprise!!!
I was wrong and stupid.
MicroScript, however, can handle the promise.
Just add the then
keyword.
The code should look like this >>>
c = test().then( function( result ) d = result end )
I improved the sample code.