-
-
Save anonymous/9d6b6d9f049a8ce12931 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use Mojo::Pg; | |
helper pg => | |
sub { state $pg = Mojo::Pg->new('postgresql://tester:testing@/test') }; | |
get '/' => sub { | |
my $c = shift; | |
my $address = $c->tx->remote_address; | |
my $port = $c->tx->remote_port; | |
$c->inactivity_timeout(300); | |
my $cb = $c->pg->pubsub->listen(visitors => sub { | |
my ($pubsub, $visitor) = @_; | |
$c->write($visitor); | |
}); | |
$c->pg->pubsub->notify(visitors => "$address:$port"); | |
$c->on(finish => sub { shift->pg->pubsub->unlisten(visitors => $cb) }); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment