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:
parent
5bac9ec725
commit
0c45a5674e
@ -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",
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user