zoukankan      html  css  js  c++  java
  • 异步请求和超时控制

    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
    ";
          print "$body
    ";
       };
         $time1=time2iso(time());
          print "$time1 is $time1
    ";
          print "11111111111111111111
    ";
    $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
    ";
          print "$body
    ";
       };
         $time1=time2iso(time());
          print "$time1 is $time1
    ";
          print "11111111111111111111
    ";
    $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秒后输出

  • 相关阅读:
    设计模式整理_单例设计模式
    设计模式整理_工厂模式
    设计模式整理_装饰者模式
    设计模式整理_观察者模式
    设计模式整理_策略模式
    JavaSE复习_7 异常
    JavaSE复习_6 枚举类
    JavaSE复习_5 Eclipse的常见操作
    pta编程题19 Saving James Bond 2
    ImportError: No module named PIL
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349943.html
Copyright © 2011-2022 走看看