I cannot work out why in this code the callback sub is called twice. The response goes to the client after the timer expires the first time, but then it triggers all over again. Code:
Output:use strict; use warnings; use AnyEvent::HTTPD; my $h = AnyEvent::HTTPD->new(port => 8123);; my $timer; $h->reg_cb ( '/test' => sub { my ($httpd,$req) = @_; $req->respond({ content => ['text/plain', sub { my ($data_cb) = @_; return unless $data_cb; print "Setting timer...\n"; $timer = AnyEvent->timer(after => 5, cb => sub { print "Sending response...\n"; $data_cb->("Hello"); $data_cb->(); }); }] }); }, ); my $c = AnyEvent::condvar; $c->recv();
I was expecting the sub to only be called once. But it ends up being called a second time? Is there any way to avoid this? Thanks!Setting timer... Sending response... Setting timer... Sending response...
In reply to AnyEvent::HTTPD -> Extra Callback after response? by sectokia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |