1/4: add real HSL to HHVM repo :)
[hiphop-php.git] / hphp / hsl / src / async / KeyedPoll.php
blobaef6045c796abe778a52441b1861d0ca02163cb0
1 <?hh
2 /*
3 * Copyright (c) 2004-present, Facebook, Inc.
4 * All rights reserved.
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
9 */
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:
19 * ```
20 * foreach ($keyed_poll await as $k => $v) {
21 * ```
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,
39 ): this {
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,
54 ): void {
55 $this->addMultiImpl($awaitables);