Skip to content

Commit

Permalink
kriswallsmith#40: Do not lose fork messages after receive
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLevti committed Feb 9, 2020
1 parent 27d0cc4 commit c021981
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Fork.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ class Fork implements DeferredInterface
private $status;
private $message;

/** @var array<int,mixed> $messages */
private $messages;

public function __construct($pid, SharedMemory $shm, $debug = false)
{
$this->defer = new Deferred();
$this->pid = $pid;
$this->shm = $shm;
$this->debug = $debug;
$this->name = '<anonymous>';
$this->messages = [];
}

/**
Expand Down Expand Up @@ -94,19 +98,17 @@ public function processWaitStatus($status)
}
}

public function receive()
public function receive(): array
{
$messages = [];

foreach ($this->shm->receive() as $message) {
if ($message instanceof ExitMessage) {
$this->message = $message;
} else {
$messages[] = $message;
$this->messages[] = $message;
}
}

return $messages;
return $this->messages;
}

public function kill($signal = SIGINT)
Expand Down Expand Up @@ -139,6 +141,11 @@ public function getError()
}
}

public function getMessages(): array
{
return $this->messages;
}

public function isSuccessful()
{
return 0 === $this->getExitStatus();
Expand Down

0 comments on commit c021981

Please sign in to comment.