public async function waitForAsync()

in src/async/Semaphore.php [47:86]


  public async function waitForAsync(Tin $value): Awaitable<Tout> {
    $gen = async {
      if (
        $this->runningCount + $this->recentOpenCount >= $this->concurrentLimit
      ) {
        $unique_id = self::$uniqueIDCounter;
        self::$uniqueIDCounter++;
        $condition = new Condition();
        $this->blocking[$unique_id] = $condition;
        await $condition->waitForNotificationAsync($this->activeGen);
        invariant(
          $this->recentOpenCount > 0,
          'Expecting at least one recentOpenCount.',
        );
        $this->recentOpenCount--;
      }
      invariant(
        $this->runningCount < $this->concurrentLimit,
        'Expecting open run slot',
      );
      $f = $this->f;
      $this->runningCount++;
      try {
        return await $f($value);
      } finally {
        $this->runningCount--;
        $next_blocked_id = C\first_key($this->blocking);
        if ($next_blocked_id !== null) {
          $next_blocked = $this->blocking[$next_blocked_id];
          unset($this->blocking[$next_blocked_id]);
          $this->recentOpenCount++;
          $next_blocked->succeed(null);
        }
      }
    };
    $this->activeGen = AwaitAllWaitHandle::fromVec(
      vec[$gen, $this->activeGen],
    );
    return await $gen;
  }