-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parcel (or analog) to data exchange between Parent and Child processes #190
Comments
Hi @hitriyvalenok! We ship two implementations of Use
You also could implement another Channels are essentially streams which return PHP values rather than only bytes. You can create a new fiber/coroutine using Below is a snippet from $cancellation = $this->deferredCancellation->getCancellation();
try {
// We get null as last message from the cluster-runner in case it's shutting down cleanly.
// In that case, join it.
/** @var ClusterMessage $message */
while ($message = $this->context->receive($cancellation)) {
$this->lastActivity = \time();
/** @psalm-suppress UnhandledMatchCondition False positive. */
match ($message->type) {
ClusterMessageType::Pong => null,
ClusterMessageType::Data => $this->handleMessage($message->data),
ClusterMessageType::Log => \array_map(
static fn (MonologHandler $handler) => $handler->handle($message->data),
$this->logger->getHandlers(),
),
ClusterMessageType::Ping => throw new \RuntimeException('Unexpected message type received'),
};
}
$this->joinFuture->await(new TimeoutCancellation(Watcher::WORKER_TIMEOUT));
} finally {
EventLoop::cancel($watcher);
$this->close();
} Hopefully this was helpful. We'll be working more on docs in the coming months and I'll consider adding an example like the above to the readme. Please reply with any additional questions (and I'll try to respond more promptly). |
Hello there! 👋 It's not an issue, rather a question 🤗 I have a worker pool with some tasks running. Workers are using consumables they may request at any time and any number of times. Ideally, I wish to use Parcel for this purpose. Parcel is a very convenient way of communicating with data, but it can't be serialized and thus you can't pass it to Task. There's also Channel, but I don't understand how to use it in more complex cases than the docs described (when you sequentially send value, receive value, return result). How to solve my challenge without crutches? Thanks!
The text was updated successfully, but these errors were encountered: