Converting a collection of Awaitables to a time-ordered AsyncGenerator in Hack
<p>I am trying to implement Rx stream/observable merging with Hack async, and a core step is described by the title. A code version of this step would look something like this:</p>

<pre class="lang-php prettyprint-override"><code>&lt;?hh // strict
async function foo(Awaitable&lt;Iterable&lt;T&gt;&gt; $collection): Awaitable&lt;void&gt; {
  $ordered_generator = async_collection_to_gen($collection) // (**)
  foreach($ordered_generator await as $v) {
    // do something with each awaited value in the time-order they are resolved
  }
}
</code></pre>

<p>However, after mulling it over, I don't think I <em>can</em> write the starred <code>(**)</code> function. I've found that at some point or another, the implementations I've tried require functionality akin to JS's <code>Promise.race</code>, which resolves when the first of a collection Promises resolves/rejects. However, all of <a href="https://docs.hhvm.com/hack/async/utility-functions" rel="nofollow noreferrer">Hack's Awaitable collection helpers</a> create an Awaitable of a <em>fully</em> resolved collection. Furthermore, Hack doesn't permit that we don't <code>await</code> async calls from <code>async function</code>s, which I've also found to be necessary.</p>

<p>Is it possible to anyone's knowledge?</p>