in reply to PSGI, Plack, Twiggy, AnyEvent and SockJS... I need help
In your code, you create the callback timer and immediately discard it, which prevents the timer from ever getting called:
sub { ... my $w = AnyEvent->timer( after => 0, interval => 5, cb => sub { $session->write('5 seconds have passed'); $w_cond->send(); } }; }
You need to keep $w alive until the timer has fired. The easiest way is the following pattern:
... my $w; $w = AnyEvent->timer( after => 0, interval => 5, cb => sub { undef $w; # cleanup! $session->write('5 seconds have passed'); $w_cond->send(); } }; ...
That way, the timer stays alive until it has fired.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: PSGI, Plack, Twiggy, AnyEvent and SockJS... I need help
by xtpu2 (Acolyte) on Apr 09, 2014 at 14:24 UTC | |
by Corion (Patriarch) on Apr 09, 2014 at 14:42 UTC | |
by xtpu2 (Acolyte) on Apr 09, 2014 at 15:29 UTC | |
by Corion (Patriarch) on Apr 09, 2014 at 15:40 UTC | |
|
Re^2: PSGI, Plack, Twiggy, AnyEvent and SockJS... I need help
by Anonymous Monk on Apr 09, 2014 at 14:56 UTC | |
by Anonymous Monk on Apr 09, 2014 at 15:23 UTC |