title: Response from service as a callback is not concurrent in actionscript?
body: <p>I am developing an AIR application for iOS/ Android and I am using a backend service for database operations. The backend service provides asynchronous API's for loading and saving the data. I happen to stumble at a piece of logic which caught my attention:</p>
  
  <p><strong>Main</strong></p>
  
  <pre><code>public funciton loadPlayerData():void
  {
      service.loadData();
  
      // Busy lock
  
      while( !service.client == true );
  
      // Do some stuff after the client is received
  }
  </code></pre>
  
  <p><strong>Service</strong></p>
  
  <pre><code>public function loadData()
  {
      // Call the external service and specify success callback as
      // onSuccess
  }
  
  public function onSuccess():void
  {
      this.client  = true;
  }
  
  public var client:Boolean  = false;
  </code></pre>
  
  <p>What I am trying to do in the above code is that I am calling an async operation on service and while it is fetching data from server, I am busy spinning waiting for the <strong>client</strong> to set <strong>true</strong> in the callback. According to my understanding, this is how locking is done for resources in operating system and all. ( Though there are more elegant solutions in operating system other than busy wait ).</p>
  
  <p>But the results are such that the <strong>Main</strong> gets stuck in an infinite busy waiting implying that onSuccess never gets called. The reason, according to my understanding is that until and unless the the current execution ends ( or when the stack of current execution is completely popped out), control is not given to the callback Function and hence my implementation results in never ending spin wheel. My basic assumption that thread is multiplexed from time point of view is flawed and thats the explanation I can deduce from the premise.</p>
  
  <p>I want to know whats the actual reason behind the above scenario? How far I am correct in my deduction and what are the details behind execution of actionscript code in scenario like these ?</p>