Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This seems to be either a timer or timeout+retry problem. If you respond right away, it works as expected.

use strict; use warnings; use AnyEvent::HTTPD; my $h = AnyEvent::HTTPD->new(port => 8123);; my $requests = {}; my $requestCounter = 0; $h->reg_cb ( '/test' => sub { my ($httpd,$req) = @_; my $request = $requestCounter; $requestCounter++; print "Starting response for ", $req->{method}, " request $req +uest\n"; $req->respond( [200, 'ok', { 'Content-Type' => 'text/html' }, '<h1>Test</h1>' ]); } ); my $c = AnyEvent::condvar; $c->recv();

Why do you want to wait instead of responding as soon as possible?

If you want to wait for an event to happen, the modern way is to either use Websockets or Push notifications. If you can't do either of those (please explain why), then the proper fallback to handle this would be cyclic calls from client to server to "pull" not yet handled events.

Leaving standard GET requests just "hanging" will lead to a number of different things:

  • Wasted resources on the server
  • Timeouts
  • Modern browsers marking the connection to your server as unreliable, therefore increasing the number of parallel TCP connections they will open to try and get a result.
  • Customer complaints
  • Getting shouted at by your system administrator

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

In reply to Re^3: AnyEvent::HTTPD -> Extra Callback after response? by cavac
in thread AnyEvent::HTTPD -> Extra Callback after response? by sectokia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found