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

Use BlockingDriver within parallel workers

Prevents infinite spawning of workers if ParallelDriver is used within a worker.
This commit is contained in:
Aaron Piotrowski 2017-07-17 23:10:17 -05:00
parent 5bac9ec725
commit 0c45a5674e
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 12 additions and 3 deletions

View File

@ -34,7 +34,7 @@
"require": {
"amphp/amp": "^2",
"amphp/byte-stream": "^1",
"amphp/parallel": "^0.1.5"
"amphp/parallel": "^0.1.8"
},
"require-dev": {
"amphp/phpunit-util": "^1",

View File

@ -12,7 +12,7 @@ use Amp\Parallel\Worker\Task;
*
* @internal
*/
class FileTask extends BlockingDriver implements Task {
class FileTask implements Task {
const ENV_PREFIX = self::class . '#';
/** @var string */
@ -142,7 +142,7 @@ class FileTask extends BlockingDriver implements Task {
case "ctime":
case "get":
case "put":
return ([$this, $this->operation])(...$this->args);
return ([new BlockingDriver, $this->operation])(...$this->args);
default:
throw new \Error("Invalid operation");

View File

@ -22,6 +22,11 @@ function filesystem(Driver $driver = null): Driver {
$driver = driver();
}
if (\defined("AMP_WORKER") && $driver instanceof ParallelDriver) {
throw new \Error("Cannot use the parallel driver within a worker");
}
Loop::setState(LOOP_STATE_IDENTIFIER, $driver);
return $driver;
}
@ -46,6 +51,10 @@ function driver(): Driver {
return new BlockingDriver;
}
if (\defined("AMP_WORKER")) { // Prevent spawning infinite workers.
return new BlockingDriver;
}
return new ParallelDriver;
}