Title: Synchronous NativeProcess in AIR using JavaScript
Tags: javascript;asynchronous;air
Question: 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?

Here is the accepted answer: 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.)
Comment for this answer: "Only after client code is finished in current frame", what does this mean as I am not using any frames?
Comment for this answer: Actually in AIR you can write application using JavaScript or action-script. As I am familiar with only JavaScript, I am writing application in it. And I have already mentioned that in question. And now I have converted whole application to asynchronous model, as I can't find any way to do it in JavaScript. Thanks for your help
Comment for this answer: No, not the frames of movieclip. The player itself renders picture frame by frame. Are you familiar with "Flash elastic racetrack" concept? If not, google it - it's the must-know thing for Flash developer.
Comment for this answer: Elastic racetrack applies to JS AIR apps too. Basically, system code isn't executed until client code exits from all the event listeners, infinite loop will only hang application. You just don't have choice but use async model.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2011:00:05/27/11', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><asynchronous><air>', 'Title': 'Synchronous NativeProcess in AIR using JavaScript', 'ViewCount': 456, 'id': 6150293, 'user_AboutMe': '', 'user_AccountId': 392574.0, 'user_DisplayName': 'Pradeep', 'user_Reputation': 1254.0, 'user_Views': 174.0, 'user_id': 753930.0}}