Remove array(...) literals from hphp/system
[hiphop-php.git] / hphp / system / php / async / vm.ns.php
blobde25d91897ef887a0c506f348c5b97e480eb7570
1 <?hh // partial
3 // These are in a separate file so they can be loaded before the things that
4 // use them
6 namespace HH\Asio {
8 /**
9 * Translate a `KeyedTraversable` of `Awaitables` into a single `Awaitable of
10 * `Map`.
12 * This function takes any `KeyedTraversable` object of `Awaitables` (i.e.,
13 * each member of the `KeyedTraversable` has a value of type of `Awaitable`,
14 * likely from a call to a function that returned `Awaitable<T>`), and
15 * transforms those `Awaitables` into one big `Awaitable` `Map`.
17 * This function is called `m` because we are returning a `m`ap of `Awaitable`.
19 * Only When you `await` or `join` the resulting `Awaitable`, will all of the
20 * key/values in the `Map` within the returned `Awaitable` be available.
22 * @deprecated use `Dict\from_async()` instead.
24 * @param $awaitables - The collection of `KeyedTraversable` awaitables.
26 * @return - An `Awaitable` of `Map`, where the `Map` was generated from
27 * each `KeyedTraversable` member in `$awaitables`.
29 async function m<Tk, Tv>(
30 KeyedTraversable<Tk, Awaitable<Tv>> $awaitables,
31 ): Awaitable<Map<Tk, Tv>> {
32 $awaitables = new Map($awaitables);
33 await AwaitAllWaitHandle::fromMap($awaitables);
34 // TODO: When systemlib supports closures
35 // return $awaitables->map($o ==> $o->result());
36 $ret = Map {};
37 foreach ($awaitables as $key => $value) {
38 $ret[$key] = \HH\Asio\result($value);
40 return $ret;
43 /**
44 * Translate a `Traversable` of `Awaitables` into a single `Awaitable` of
45 * `Vector`.
47 * This function takes any `Traversable` object of `Awaitables` (i.e., each
48 * member of the `Traversable` is of type of `Awaitable`, likely from a call
49 * to a function that returned `Awaitable<T>`), and transforms those
50 * `Awaitables` into one big `Awaitable` `Vector`.
52 * This function is called `v` we are returning a `v`ector of `Awaitable`.
54 * Only When you `await` or `join` the resulting `Awaitable`, will all of the
55 * values in the `Vector` within the returned `Awaitable` be available.
57 * @deprecated use `Vec\from_async()` instead.
59 * @param $awaitables - The collection of `Traversable` awaitables.
61 * @return - An `Awaitable` of `Vector`, where the `Vector` was generated from
62 * each `Traversable` member in `$awaitables`.
64 async function v<Tv>(
65 Traversable<Awaitable<Tv>> $awaitables,
66 ): Awaitable<Vector<Tv>> {
67 $awaitables = new Vector($awaitables);
68 await AwaitAllWaitHandle::fromVector($awaitables);
69 // TODO: When systemlib supports closures
70 // return $awaitables->map($o ==> $o->result());
71 $ret = Vector {};
72 foreach ($awaitables as $value) {
73 $ret[] = \HH\Asio\result($value);
75 return $ret;
78 /**
79 * Translate a varargs of `Awaitable`s into a single `Awaitable<(...)>`.
80 * This function's behavior cannot be expressed with type hints,
81 * so it's hardcoded in the typechecker:
83 * HH\Asio\va(Awaitable<T1>, Awaitable<T2>, ... , Awaitable<Tn>)
85 * will return
87 * Awaitable<(T1, T2, ..., Tn)>
89 * @deprecated Use `Tuple\from_async()` instead.
90 * @fbdeprecated Use `genva()` instead.
92 async function va(...$awaitables): Awaitable/*<(...)>*/ {
93 await AwaitAllWaitHandle::fromArray($awaitables);
94 $ret = varray[];
95 foreach ($awaitables as $value) {
96 $ret[] = \HH\Asio\result($value);
98 return $ret;
101 } // namespace HH\Asio