• 追加された行はこの色です。
  • 削除された行はこの色です。
* AnyEvent::Timer [#p55a52ec]


 #!/usr/bin/env perl
 
 use strict;
 use warnings;
 use 5.012;
 use AnyEvent;
 
 my $cv = AnyEvent->condvar;
 $cv->cb(
     sub {
         say "callback is called.";
     }
 );
 my $timer;
 $timer = AnyEvent->timer(
     after    => 3,
     interval => 0,
     cb       => sub {
         say '3 secs passed.';
         undef $timer;
         $cv->send;
     }
 );
 say "Start.";
 $cv->recv;
 say "End.";

- AnyEvent->timer()のcbで指定しているブロックがイベントループ。
- メインループの$cv->recvで、イベントループで$cv->sendするのを「待つ」。が、$cv->recvを削除すると、何も待つものがないので、イベントループは実行されない。



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS