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 milliseconds

  • on_connect - Callback when client connects

  • on_close - Callback when stream ends

  • headers - Additional headers to send

EVENT FORMAT

Events are hashrefs with optional keys:

  • data - Event data (required for client to receive)

  • event - Event type name

  • id - Event ID for reconnection