From 6ad1b8e55f47673bf5a9665e84ba40e8020b7d02 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Tue, 16 May 2017 19:55:24 -0500 Subject: [PATCH] Update for object-based uv extension --- lib/UvDriver.php | 15 +++++---------- lib/UvHandle.php | 15 +++++++++------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/UvDriver.php b/lib/UvDriver.php index ae10de6..61fedd9 100644 --- a/lib/UvDriver.php +++ b/lib/UvDriver.php @@ -2,29 +2,24 @@ namespace Amp\File; -use Amp\{ Coroutine, Deferred, Failure, Loop, Promise, Success }; +use Amp\{ Coroutine, Deferred, Loop, Promise, Success }; class UvDriver implements Driver { /** @var \Amp\Loop\Driver */ private $driver; - /** @var resource Loop resource of type uv_loop. */ + /** @var \UVLoop|resource Loop resource of type uv_loop or instance of \UVLoop. */ private $loop; /** @var string Loop onReadable watcher. */ private $busy; /** - * @param \Amp\Loop\Driver $driver + * @param \Amp\Loop\UvDriver $driver */ - public function __construct(Loop\Driver $driver) { - $loop = $driver->getHandle(); - if (!is_resource($loop) || get_resource_type($loop) != "uv_loop") { - throw new \InvalidArgumentException("Expected a driver whose underlying loop is an uv_loop"); - } - + public function __construct(Loop\UvDriver $driver) { $this->driver = $driver; - $this->loop = $loop; + $this->loop = $driver->getHandle(); // dummy handle to be able to tell the loop that there is work being done and it shouldn't abort if there are no other watchers at a given moment $this->busy = $driver->repeat(PHP_INT_MAX, function(){ }); diff --git a/lib/UvHandle.php b/lib/UvHandle.php index 9771380..c836b35 100644 --- a/lib/UvHandle.php +++ b/lib/UvHandle.php @@ -21,12 +21,15 @@ class UvHandle implements Handle { private $isActive = false; private $isCloseInitialized = false; - public function __construct(Loop\Driver $driver, $busy, $fh, $path, $mode, $size) { - $loop = $driver->getHandle(); - if (!is_resource($loop) || get_resource_type($loop) != "uv_loop") { - throw new \InvalidArgumentException("Expected a driver whose underlying loop is an uv_loop"); - } - + /** + * @param \Amp\Loop\UvDriver $driver + * @param string $busy Watcher ID. + * @param resource $fh File handle. + * @param string $path + * @param string $mode + * @param int $size + */ + public function __construct(Loop\UvDriver $driver, string $busy, $fh, string $path, string $mode, int $size) { $this->driver = $driver; $this->busy = $busy; $this->fh = $fh;