That makes way too much sense!  Should have thought of that...but had assumed a 
recurring timer had to run inside a route.  I'll give that a go in the morning!

Get Outlook for iOS




On Tue, Aug 9, 2016 at 12:25 AM -0400, "Scott Wiersdorf" 
<[email protected]> wrote:










On Monday, August 8, 2016 at 9:20:09 PM UTC-6, Aaron wrote:Is there a way to do 
the database polling in a single loop that then sends the notification out to 
all connected web socket clients?  Does this need to be set up as an entirely 
other application that does the polling and then have the web socket route 
listen for messages from it?  Or am I overcomplicating this horribly?
What about something like (untested):
my %clients = ();Mojo::IOLoop->recurring(5 => sub {    ## poll the db    ...
    ## broadcast to all connected clients    $_->send({text => "updated"}) for 
values %clients;});

## routes here...
When a client connects, store the socket (I believe $ws will be stringified as 
the key):

    $c->on(message => sub { my $ws = shift; $clients{$ws} = $ws })
and when a client disconnects, remove the socket:
    $c->on(finish => sub { my $ws = shift; delete $clients{$ws} });
Scott





-- 

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 https://groups.google.com/group/mojolicious.

For more options, visit https://groups.google.com/d/optout.






-- 
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 https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to