From dd708506828b2fd42444c52e0a70f035f244308a Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 26 May 2016 00:09:50 -0500 Subject: [PATCH] Remove driver argument --- lib/functions.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 43733e4..8deb6d9 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -4,7 +4,6 @@ namespace Amp; use Interop\Async\Awaitable; use Interop\Async\Loop; -use Interop\Async\LoopDriver; /** * Returns a new function that when invoked runs the Generator returned by $worker as a coroutine. @@ -48,14 +47,20 @@ function rethrow(Awaitable $awaitable) { * * @throws \Throwable|\Exception Awaitable failure reason. */ -function wait(Awaitable $awaitable, LoopDriver $driver = null) { - Loop::execute(function () use (&$value, &$exception, $awaitable) { - $awaitable->when(function ($e, $v) use (&$value, &$exception) { +function wait(Awaitable $awaitable) { + $resolved = false; + Loop::execute(function () use (&$resolved, &$value, &$exception, $awaitable) { + $awaitable->when(function ($e, $v) use (&$resolved, &$value, &$exception) { Loop::stop(); + $resolved = true; $exception = $e; $value = $v; }); - }, $driver ?: Loop::get()); + }); + + if (!$resolved) { + throw new \LogicException("Loop emptied without resolving awaitable"); + } if ($exception) { throw $exception;