I am creating application in AIR using JavaScript. Many of my functions requires text returned by native process. But native process, in AIR gives values asynchronously by calling function on STANDARD_OUTPUT_DATA Event.
Is there is any way to get that value synchronously, like waiting for a function till its execution is over.
Here is sample code :
var textReceived;
function callbackFunction()
{
textReceived= getTextfromProcess();
}
function chkProc()
{
process.addEventListener(STANDARD_OUTPUT_DATA, callbackFunction);
//This is AIR's function which give text asynchronously
}
function sqlExc(sql)
{
chkProc();
//wait here before returning
return textReceived;
}
As JavaScript runs on single thread, I can not use infinite loop with break.
Is there any way of achieving this?
NativeProcess has no blocking (synchronous) methods. BTW, infinite loop would not help here – to let runtime go process events, client code must exit all functions. Only after client code is finished in current frame, runtime communicates with native process (and network, and everything else.)