mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
5.5+ yield compat
This commit is contained in:
parent
b6769f1ef4
commit
03806a5358
@ -230,7 +230,8 @@ class UvFilesystem implements Filesystem {
|
|||||||
|
|
||||||
private function doGet($path): \Generator {
|
private function doGet($path): \Generator {
|
||||||
$this->reactor->addRef();
|
$this->reactor->addRef();
|
||||||
if (!$fh = yield $this->doFsOpen($path, $flags = \UV::O_RDONLY, $mode = 0)) {
|
$promise = $this->doFsOpen($path, $flags = \UV::O_RDONLY, $mode = 0);
|
||||||
|
if (!$fh = (yield $promise)) {
|
||||||
$this->reactor->delRef();
|
$this->reactor->delRef();
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
"Failed opening file handle: {$path}"
|
"Failed opening file handle: {$path}"
|
||||||
@ -238,7 +239,7 @@ class UvFilesystem implements Filesystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$promisor = new Deferred;
|
$promisor = new Deferred;
|
||||||
$stat = yield $this->doFsStat($fh);
|
$stat = (yield $this->doFsStat($fh));
|
||||||
if (empty($stat)) {
|
if (empty($stat)) {
|
||||||
$this->reactor->delRef();
|
$this->reactor->delRef();
|
||||||
$promisor->fail(new \RuntimeException(
|
$promisor->fail(new \RuntimeException(
|
||||||
@ -252,7 +253,7 @@ class UvFilesystem implements Filesystem {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$buffer = yield $this->doFsRead($fh, $offset = 0, $stat["size"]);
|
$buffer = (yield $this->doFsRead($fh, $offset = 0, $stat["size"]));
|
||||||
if ($buffer === false ) {
|
if ($buffer === false ) {
|
||||||
\uv_fs_close($this->loop, $fh, function() use ($promisor) {
|
\uv_fs_close($this->loop, $fh, function() use ($promisor) {
|
||||||
$this->reactor->delRef();
|
$this->reactor->delRef();
|
||||||
@ -268,7 +269,7 @@ class UvFilesystem implements Filesystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return yield $promisor->promise();
|
yield "return" => yield $promisor->promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function doFsOpen($path, $flags, $mode) {
|
private function doFsOpen($path, $flags, $mode) {
|
||||||
@ -315,7 +316,8 @@ class UvFilesystem implements Filesystem {
|
|||||||
$flags = \UV::O_WRONLY | \UV::O_CREAT;
|
$flags = \UV::O_WRONLY | \UV::O_CREAT;
|
||||||
$mode = \UV::S_IRWXU | \UV::S_IRUSR;
|
$mode = \UV::S_IRWXU | \UV::S_IRUSR;
|
||||||
$this->reactor->addRef();
|
$this->reactor->addRef();
|
||||||
if (!$fh = yield $this->doFsOpen($path, $flags, $mode)) {
|
$promise = $this->doFsOpen($path, $flags, $mode);
|
||||||
|
if (!$fh = (yield $promise)) {
|
||||||
$this->reactor->delRef();
|
$this->reactor->delRef();
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
"Failed opening write file handle"
|
"Failed opening write file handle"
|
||||||
@ -337,6 +339,6 @@ class UvFilesystem implements Filesystem {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return yield $promisor->promise();
|
yield "return" => yield $promisor->promise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user