1
0
mirror of https://github.com/danog/file.git synced 2024-11-26 11:54:54 +01:00

Update for object-based uv extension

This commit is contained in:
Aaron Piotrowski 2017-05-16 19:55:24 -05:00
parent a05915f953
commit 6ad1b8e55f
2 changed files with 14 additions and 16 deletions

View File

@ -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(){ });

View File

@ -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;