1
0
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:
Aaron Piotrowski 2021-09-17 14:52:07 -05:00
parent 0d3f068fbf
commit b63b26b063
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -30,6 +30,9 @@ final class Future
// Directly iterate in case of an array, because there can't be suspensions during iteration
if (\is_array($futures)) {
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->complete();
@ -39,6 +42,9 @@ final class Future
defer(static function () use ($futures, $iterator): void {
try {
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->complete();