Documentation

Future

Table of Contents

Classes

UnhandledFutureError
Will be thrown to the event loop error handler in case a future exception is not handled.

Functions

awaitFirst()  : T
Unwraps the first completed future.
awaitAny()  : Tv
Awaits the first successfully completed future, ignoring errors.
awaitAnyN()  : array<string|int, mixed>
Awaits the first N successfully completed futures, ignoring errors.
awaitAll()  : array<string|int, mixed>
Awaits all futures to complete or error.
await()  : array<string|int, mixed>
Awaits all futures to complete or aborts if any errors.

Functions

awaitFirst()

Unwraps the first completed future.

awaitFirst(iterable<string|int, Future<string|int, T>> $futures[, Cancellation|null $cancellation = null ]) : T

If you want the first future completed without an error, use awaitAny() instead.

Parameters
$futures : iterable<string|int, Future<string|int, T>>
$cancellation : Cancellation|null = null

Optional cancellation.

Tags
template
throws
CompositeLengthException

If $futures is empty.

Return values
T

awaitAny()

Awaits the first successfully completed future, ignoring errors.

awaitAny(iterable<Tk, Future<string|int, Tv>> $futures[, Cancellation|null $cancellation = null ]) : Tv

If you want the first future completed, successful or not, use awaitFirst() instead.

Parameters
$futures : iterable<Tk, Future<string|int, Tv>>
$cancellation : Cancellation|null = null

Optional cancellation.

Tags
template
template
throws
CompositeException

If all futures errored.

throws
CompositeLengthException

If $futures is empty.

Return values
Tv

awaitAnyN()

Awaits the first N successfully completed futures, ignoring errors.

awaitAnyN(positive-int $count, iterable<Tk, Future<string|int, Tv>> $futures[, Cancellation|null $cancellation = null ]) : array<string|int, mixed>
Parameters
$count : positive-int
$futures : iterable<Tk, Future<string|int, Tv>>
$cancellation : Cancellation|null = null

Optional cancellation.

Tags
template
template
throws
CompositeException

If too many futures errored.

throws
CompositeLengthException

If $futures is empty.

Return values
array<string|int, mixed>

awaitAll()

Awaits all futures to complete or error.

awaitAll(iterable<Tk, Future<string|int, Tv>> $futures[, Cancellation|null $cancellation = null ]) : array<string|int, mixed>

This awaits all futures without aborting on first error (unlike await()).

Parameters
$futures : iterable<Tk, Future<string|int, Tv>>
$cancellation : Cancellation|null = null

Optional cancellation.

Tags
template
template
Return values
array<string|int, mixed>

await()

Awaits all futures to complete or aborts if any errors.

await(iterable<Tk, Future<string|int, Tv>> $futures[, Cancellation|null $cancellation = null ]) : array<string|int, mixed>

The returned array keys will be in the order the futures resolved, not in the order given by the iterable. Sort the array after completion if necessary.

This is equivalent to awaiting all futures in a loop, except that it aborts as soon as one of the futures errors instead of relying on the order in the iterable and awaiting the futures sequentially.

Parameters
$futures : iterable<Tk, Future<string|int, Tv>>
$cancellation : Cancellation|null = null

Optional cancellation.

Tags
template
template
Return values
array<string|int, mixed>

        
On this page

Search results