Exception
SubscriberLagException
A subscription fell further behind its topic than its $maxLag seconds, see Subscription.
Introduction#
Thrown from the subscription's loop, which ends. A client that can't keep up is better
disconnected: it reconnects and catches up from storage. An OrderedChannel subscription
also throws it when messages were lost because its worker did not run for about 30 s.
Class synopsis#
class SubscriberLagException extends RuntimeException implements \Stringable, \Throwable {
}Examples#
use Swerve\SubscriberLagException;
use Swerve\Swerve;
phasync::run(function () {
$subscription = Swerve::subscribe('prices', maxLag: 0.1);
Swerve::publish('prices', 101.5);
phasync::sleep(0.3); // busy elsewhere for longer than maxLag
try {
foreach ($subscription as $price) {
echo "price $price\n";
}
} catch (SubscriberLagException) {
echo "fell behind: disconnect, and let the client catch up from storage\n";
}
});Output
fell behind: disconnect, and let the client catch up from storage
try {
foreach (Swerve::subscribe('chat', maxLag: 5.0) as $message) {
$ws->send(json_encode($message));
}
} catch (SubscriberLagException) {
$ws->end(1013, 'too slow');
}See also#
Swerve::subscribeReceive what is published to$topicfrom now on.SubscriptionThe messages published to a topic, fromSwerve::subscribe: iterate over it to receive them.