http://www.perlmonks.org?node_id=1081621


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.