1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 12:35:02 +01:00

Throw InvalidArgumentException if argument to resolve() is neither callable nor an instance of Generator

This commit is contained in:
Niklas Keller 2016-05-11 18:49:25 +02:00
parent 92e004264c
commit d9aa8573f0

View File

@ -757,10 +757,12 @@ function coroutine(callable $func) {
*/
function resolve($generator) {
if (!$generator instanceof \Generator) {
if (is_callable($generator)) {
$generator = call_user_func($generator);
if (!is_callable($generator)) {
throw new \InvalidArgumentException('Coroutine to resolve must be callable or instance of Generator');
}
$generator = call_user_func($generator);
if (!$generator instanceof \Generator) {
throw new \LogicException('Callable passed to resolve() did not return an instance of Generator');
}