Make sure that tcp_server is listening

Mike Schilli anyevent at perlmeister.com
Thu Mar 1 00:11:30 CET 2012


For convenient testing, I often define a client and a server in the same
process, i.e. calling AnyEvent::Socket::tcp_server, make sure it's up
and then tcp_connect all in one test script.

Since tcp_server offers a 'prepare' callback that it jumps to right
*before* it starts listening to the socket, I've had problems using

     tcp_server undef, 8888, sub { ... }, sub { tcp_connect(...) };

since tcp_connect() will bomb at this point because there's no server.

I've worked around the problem by delaying the tcp_connect via 
AnyEvent->timer(), but I'd rather have a deterministic method.
Is there a way to trigger an event (via Object::Event or some such)
right *after* the server started listing?

-- -- Mike

anyevent at perlmeister.com



More information about the anyevent mailing list