mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +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": {
|
"require": {
|
||||||
"amphp/amp": "^2",
|
"amphp/amp": "^2",
|
||||||
"amphp/byte-stream": "^1",
|
"amphp/byte-stream": "^1",
|
||||||
"amphp/parallel": "^0.1.5"
|
"amphp/parallel": "^0.1.8"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"amphp/phpunit-util": "^1",
|
"amphp/phpunit-util": "^1",
|
||||||
|
@ -12,7 +12,7 @@ use Amp\Parallel\Worker\Task;
|
|||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class FileTask extends BlockingDriver implements Task {
|
class FileTask implements Task {
|
||||||
const ENV_PREFIX = self::class . '#';
|
const ENV_PREFIX = self::class . '#';
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@ -142,7 +142,7 @@ class FileTask extends BlockingDriver implements Task {
|
|||||||
case "ctime":
|
case "ctime":
|
||||||
case "get":
|
case "get":
|
||||||
case "put":
|
case "put":
|
||||||
return ([$this, $this->operation])(...$this->args);
|
return ([new BlockingDriver, $this->operation])(...$this->args);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \Error("Invalid operation");
|
throw new \Error("Invalid operation");
|
||||||
|
@ -22,6 +22,11 @@ function filesystem(Driver $driver = null): Driver {
|
|||||||
|
|
||||||
$driver = 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);
|
Loop::setState(LOOP_STATE_IDENTIFIER, $driver);
|
||||||
return $driver;
|
return $driver;
|
||||||
}
|
}
|
||||||
@ -46,6 +51,10 @@ function driver(): Driver {
|
|||||||
return new BlockingDriver;
|
return new BlockingDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\defined("AMP_WORKER")) { // Prevent spawning infinite workers.
|
||||||
|
return new BlockingDriver;
|
||||||
|
}
|
||||||
|
|
||||||
return new ParallelDriver;
|
return new ParallelDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user