public function send($data) : \Generator
{
// Serialize the data to send into the channel.
try {
$serialized = serialize($data);
} catch (\Throwable $exception) {
throw new SerializationException('The given data cannot be sent because it is not serializable.', $exception);
}
$length = strlen($serialized);
try {
yield from $this->write->write(pack('CL', 0, $length) . $serialized);
} catch (\Throwable $exception) {
throw new ChannelException('Sending on the channel failed. Did the context die?', $exception);
}
return $length;
}