Skip to content

Commit

Permalink
Adjust: the multi-process collection event set
Browse files Browse the repository at this point in the history
  • Loading branch information
cclilshy committed Aug 27, 2024
1 parent ed42aaa commit 00dc671
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
23 changes: 2 additions & 21 deletions src/Core/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
use function call_user_func;
use function P\cancel;
use function P\cancelAll;
use function P\defer;
use function P\getIdentities;
use function P\promise;
use function P\tick;
use function pcntl_fork;
Expand Down Expand Up @@ -235,16 +235,11 @@ public function task(Closure $closure): Task|false
/**
* It is necessary to ensure that the final closure cannot be escaped by any means.
*/

// forget all events
cancelAll();

$this->forked();

// mouth user func
defer(function () use ($closure, $args) {
call_user_func($closure, ...$args);
});
call_user_func($closure, ...$args);

// Whether it belongs to the PRipple coroutine space
if(Coroutine::Coroutine()->isCoroutine()) {
Expand All @@ -256,20 +251,6 @@ public function task(Closure $closure): Task|false
tick();
exit(0);
}

// // call user mount
// try {
// call_user_func($closure, ...$args);
// } catch (Throwable) {
// exit(1);
// }
//
// // Determine whether the event list is empty
// if(count(getIdentities()) === 0) {
// exit(0);
// }
//
// throw new EscapeException('The process is abnormal.');
}

if(empty($this->process2runtime)) {
Expand Down
13 changes: 8 additions & 5 deletions src/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Psc\Utils\Output;
use Psc\Utils\Serialization\Zx7e;

use function P\delay;
use function P\promise;
use function socket_create_pair;
use function socket_export_stream;
Expand Down Expand Up @@ -192,7 +193,7 @@ public function commandToAll(Command $command): void
public function syncId(): Promise
{
return promise(function (Closure $resolve, Closure $reject) {
$id = spl_object_hash($resolve);
$id = spl_object_hash($resolve);
$command = Command::make(Worker::COMMAND_SYNC_ID, ['id' => $id]);
$this->command($command);

Expand All @@ -217,10 +218,10 @@ private function _onCommand(Command $workerCommand): void
$this->onReload();
break;
case Worker::COMMAND_SYNC_ID:
$id = $workerCommand->arguments['id'];
$id = $workerCommand->arguments['id'];
$sync = $workerCommand->arguments['sync'];

if($callback = $this->queue[$id] ?? null) {
if ($callback = $this->queue[$id] ?? null) {
unset($this->queue[$id]);
$callback['resolve']($sync);
}
Expand Down Expand Up @@ -305,10 +306,12 @@ private function guard(Manager $manager, int $index): bool
unset($this->streams[$index]);
}

if(isset($this->runtimes[$index])) {
if (isset($this->runtimes[$index])) {
unset($this->runtimes[$index]);
}
$this->guard($manager, $index);
\P\delay(function () use ($manager, $index) {
$this->guard($manager, $index);
}, 0.1);
});
return true;
}
Expand Down

0 comments on commit 00dc671

Please sign in to comment.