mirror of
https://github.com/danog/amp.git
synced 2025-01-22 21:31:18 +01:00
Throw if Future::iterate() is provided something other than futures
This commit is contained in:
parent
0d3f068fbf
commit
b63b26b063
@ -30,6 +30,9 @@ final class Future
|
|||||||
// Directly iterate in case of an array, because there can't be suspensions during iteration
|
// Directly iterate in case of an array, because there can't be suspensions during iteration
|
||||||
if (\is_array($futures)) {
|
if (\is_array($futures)) {
|
||||||
foreach ($futures as $key => $future) {
|
foreach ($futures as $key => $future) {
|
||||||
|
if (!$future instanceof self) {
|
||||||
|
throw new \TypeError('Array must only contain instances of ' . self::class);
|
||||||
|
}
|
||||||
$iterator->enqueue($future->state, $key, $future);
|
$iterator->enqueue($future->state, $key, $future);
|
||||||
}
|
}
|
||||||
$iterator->complete();
|
$iterator->complete();
|
||||||
@ -39,6 +42,9 @@ final class Future
|
|||||||
defer(static function () use ($futures, $iterator): void {
|
defer(static function () use ($futures, $iterator): void {
|
||||||
try {
|
try {
|
||||||
foreach ($futures as $key => $future) {
|
foreach ($futures as $key => $future) {
|
||||||
|
if (!$future instanceof self) {
|
||||||
|
throw new \TypeError('Iterable must only provide instances of ' . self::class);
|
||||||
|
}
|
||||||
$iterator->enqueue($future->state, $key, $future);
|
$iterator->enqueue($future->state, $key, $future);
|
||||||
}
|
}
|
||||||
$iterator->complete();
|
$iterator->complete();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user