NAME
PAGI::App::SSE::Stream - Server-Sent Events streaming
SYNOPSIS
use PAGI::App::SSE::Stream;
my $app = PAGI::App::SSE::Stream->new(
generator => async sub ($send_event, $scope) {
for my $i (1..10) {
await $send_event->({ data => time() });
await IO::Async::Loop->new->delay_future(after => 1);
}
},
)->to_app;
DESCRIPTION
Server-Sent Events streaming application. Provides a generator-based API for sending events to clients.
OPTIONS
generator- Async coderef receiving ($send_event, $scope)retry- Reconnection time in millisecondson_connect- Callback when client connectson_close- Callback when stream endsheaders- Additional headers to send
EVENT FORMAT
Events are hashrefs with optional keys:
data- Event data (required for client to receive)event- Event type nameid- Event ID for reconnection