- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- バックアップ を表示
- Perl/イベント駆動/AnyEvent-Timer へ行く。
- 1 (2012-03-07 (水) 17:37:08)
* 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を削除すると、何も待つものがないので、イベントループは実行されない。