title: Return synchronously when a React/Promise is resolved
body: <p>I need to return from a function call once a React/Promise has been resolved. The basic idea is to fake a synchronous call from an ansynchronous one. This means that the outer function must return a value once a promise has been resolved or rejected.</p>
  
  <p>This is to create a driver for RedBeanPHP using React/Mysql. I am aware that this will likely lead to CPU starvation in the React event loop.</p>
  
  <p>My initial idea was to use a generator then call yield inside a <code>\React\Promise\Deferred::then</code> callback.</p>
  
  <pre><code>function synchronous()
  {
      $result = asynchronous();
  }
  
  function asynchronous()
  {
      $deferred = new \React\Promise\Deferred;
  
      $sleep = function() use ($deferred)
      {
          sleep(5);
          $deferred-&gt;resolve(true);
      };
  
      $deferred-&gt;then(function($ret) {
          yield $ret;
      });
  
      $sleep();
  }
  </code></pre>
  
  <p>The PHP generator class, AFAICT, is only directly constructable by the PHP engine itself. The then callback would need to directly invoke send on the generator of the asynchronous function for this to work.</p>