get '/api/test' => sub{
my $c=shift;
sleep(10);
$c->render(text =>"this is test 1229")
};
centos6.5:/root#perl as.pl
$time1 is 2016-12-29 22:52:33
11111111111111111111
/**************
centos6.5:/root#cat as.pl
use AnyEvent::HTTP;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my $cv = AnyEvent->condvar;
http_request GET => 'http://192.168.11.185:3000/api/test',timeout => 5, sub {
my ($body, $hdr) = @_;
$time2=time2iso(time());
print "\$time2 is $time2\n";
print "$body\n";
};
$time1=time2iso(time());
print "\$time1 is $time1\n";
print "11111111111111111111\n";
$cv->recv();
centos6.5:/root#perl as.pl
$time1 is 2016-12-29 22:52:33
11111111111111111111
$time2 is 2016-12-29 22:52:38
此时5秒钟就超时不输出了
centos6.5:/root#cat as.pl
use AnyEvent::HTTP;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my $cv = AnyEvent->condvar;
http_request GET => 'http://192.168.11.185:3000/api/test',timeout => 20, sub {
my ($body, $hdr) = @_;
$time2=time2iso(time());
print "\$time2 is $time2\n";
print "$body\n";
};
$time1=time2iso(time());
print "\$time1 is $time1\n";
print "11111111111111111111\n";
$cv->recv();
centos6.5:/root#perl as.pl
$time1 is 2016-12-29 22:54:14
11111111111111111111
$time2 is 2016-12-29 22:54:24
this is test 1229
此时隔10秒后输出
异步请求和超时控制
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:C\C++ 内存对齐
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot中异步请求和异步调用
阅读文本大概需要20分钟。一、SpringBoot中异步请求的使用1、异步请求与同步请求特点:可以先释放容器
spring 异步请求 ide 异步调用 异步方法 -
java 异步请求超时处理 java异步http请求
同步与异步概念辨析同步(synchronous)和异步(asynchronous)通常用于描述在执行操作时是否需要等待某个操作完成,以及如何处理返回结果• 类比生活
java 异步请求超时处理 java http 同步 异步