| 1 | 1 | ▶ | use v5.40; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use experimental 'signatures'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use Future::AsyncAwait; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use PAGI::Nano; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | # Ports PAGI's 05-sse-broadcaster (and PAGI-Tools' sse-dashboard) to PAGI::Nano. | ||
| 7 | # An imperative SSE handler sends a series of named events with ids (ids let a | ||
| 8 | # reconnecting client resume via Last-Event-ID). For a long-lived feed you would | ||
| 9 | # loop with $s->keepalive and a timer; here we send a fixed burst. | ||
| 10 | # | ||
| 11 | # pagi-server app.pl | ||
| 12 | # curl -N http://127.0.0.1:5000/events | ||
| 13 | |||
| 14 | 1 | ▶ | my $app = app { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 15 | 1 | ▶ | sse '/events' => async sub ($c) { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||
| 16 | 1 | my $s = $c->sse; | |
| 17 | 1 | for my $i (1 .. 5) { | |
| 18 | 5 | await $s->send_event(event => 'tick', id => $i, data => "ping $i"); | |
| 19 | } | ||
| 20 | 1 | await $s->close; | |
| 21 | 1 | }; | |
| 22 | 1 | }; | |
| 23 | |||
| 24 | 1 | $app; | |