http-useragent icon indicating copy to clipboard operation
http-useragent copied to clipboard

Timeout support

Open tokuhirom opened this issue 9 years ago • 4 comments

HTTP::UserAgent should have timeout feature.

tokuhirom avatar Oct 14 '15 13:10 tokuhirom

Hi, it probably should, however I don''t think the IO::Socket::INET supports a timeout currentlly and I'm not sure if there's a nice way to do it otherwise.

But of course if you have a suggestion .....

jonathanstowe avatar Oct 14 '15 15:10 jonathanstowe

I've had a think about this and I think it can be implemented with a small bit of asynchronous code to perform the timeout.

I want to do some refactoring around the request() method first so that I can isolate the connection parts in its own method first.

jonathanstowe avatar Oct 19 '15 20:10 jonathanstowe

I've tried this before but it did not seem to actually work

await Promise.anyof(
    Promise.in(60),
    start {
       # make request
    },
);

ugexe avatar Oct 19 '15 20:10 ugexe

@ugexe yeah that's https://rt.perl.org/Ticket/Display.html?id=126390 but for me:

await Promise.anyof(Promise.in(60), start {
   my $sock = IO::Socket::INET.new(host => 'localhost', port => 80, timeout => 10);
   $sock.print("GET /\r\n\r\n");
   say $sock.recv(:bin);
   $sock.close;
});

Works fine here. Obviously that's somewhat different to the actually code but you get the idea.

jonathanstowe avatar Oct 19 '15 21:10 jonathanstowe