For sake of brevity here is snippet of code from working version. I have
an executable that runs for the life of the application and Websocket
connections (from 1 or more clients) that need to get output from the
executable.
Ideally the logic would be that once output from excutable is available it
would be sent to any clients that currently have a Websocket connection
with the Mojolicious application.
use Mojolicious::Lite;
use Mojo::IOLoop;
use IO::Async::Process;
use IO::Async::Loop::Mojo;
my $loop = IO::Async::Loop::Mojo->new;
my $process = IO::Async::Process->new(
command => [ "/bin/ping", "localhost" ],
stdout => {
on_read => sub {
my ( $stream, $buffref, $eof ) = @_;
while ( $$buffref =~ s/^(.*)\n// ) {
app->log->info("PING wrote: $1");
# I Want to get $1 (or a modification of it) sent via the
Websocket connection(s) $ws below.
}
return 0;
},
},
on_finish => sub {
my ( $pid, $exitcode ) = @_;
my $status = ( $exitcode >> 8 );
},
);
$loop->add($process);
websocket '/monitor' => sub {
my $self = shift;
$self->on(
json => sub {
my ( $ws, $row ) = @_;
my $html = $ws->render_to_string( 'table', rows => [$row] );
$ws->send( { json => { row => $html } } );
}
);
};
app->start;
How is this done in Mojolicious?
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.