Skip to content

Commit

Permalink
Throw InvalidArgumentException if argument to resolve() is neither ca…
Browse files Browse the repository at this point in the history
…llable nor an instance of Generator
  • Loading branch information
kelunik committed May 11, 2016
1 parent 92e0042 commit d9aa857
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit d9aa857

Please sign in to comment.