Amon2::Plugin::Web::Streaming - streaming support for Amon2
__PACKAGE__->load_plugin(qw/Web::Streaming/); any '/poll' => sub { my $c = shift; return $c->streaming(sub { my $respond = shift; ... $respond->write([200, [], ['OK']]); }); }; any '/poll_json' => sub { my $c = shift; return $c->streaming_json(sub { my $writer = shift; ... $writer->write_json($dat); $writer->close; }); };
This is an Amon2 plugin to supoprt streaming.
You MUST use the http server supporting psgi.streaming.
You can return delayed response for PSGI spec.
Argument for $code is $respond. It's same as a argument for PSGI callback.
$respond
It's a short hand utility to publish streaming JSON.
The arugment is instance of Amon2::Plugin::Web::Streaming::Writer.
Do not create the instance directly.
Write a $data as JSON for the socket.
Close the socket.
PSGI
To install Amon2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Amon2
CPAN shell
perl -MCPAN -e shell install Amon2
For more information on module installation, please visit the detailed CPAN module installation guide.