3 * Copyright (c) 2004-present, Facebook, Inc.
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
11 namespace HH\Lib\Async
;
13 /** A keyed variant of `Poll`.
15 * See `Poll` if you do not need to preserve keys.
17 * Keys are retrieved with:
20 * foreach ($keyed_poll await as $k => $v) {
23 * ===== WARNING ===== WARNING ===== WARNING ===== WARNING ===== WARNING =====
25 * See detailed warning for `BasePoll`
27 * ===== WARNING ===== WARNING ===== WARNING ===== WARNING ===== WARNING =====
29 final class KeyedPoll
<Tk
, Tv
>
30 extends BasePoll
<Tk
, Tv
>
31 implements AsyncKeyedIterator
<Tk
, Tv
> {
33 /** Create a `KeyedPoll` from the specified list of awaitables.
35 * See `Poll` if keys are unimportant.
37 public static function from(
38 KeyedTraversable
<Tk
, Awaitable
<Tv
>> $awaitables,
40 return self
::fromImpl($awaitables);
43 /** Add a single awaitable to the poll.
45 * The key is retrieved with `foreach ($poll await as $k => $v) {}`
47 public function add(Tk
$key, Awaitable
<Tv
> $awaitable): void
{
48 $this->addImpl($key, $awaitable);
51 /** Add multiple keys and awaitables to the poll */
52 public function addMulti(
53 KeyedTraversable
<Tk
, Awaitable
<Tv
>> $awaitables,
55 $this->addMultiImpl($awaitables);