Skip to content

Instantly share code, notes, and snippets.

@sugar84
Created October 22, 2011 11:21
Show Gist options
  • Select an option

  • Save sugar84/1305887 to your computer and use it in GitHub Desktop.

Select an option

Save sugar84/1305887 to your computer and use it in GitHub Desktop.
asynchronous timer
#!/usr/bin/env perl
use common::sense;
use AnyEvent;
use AnyEvent::Util qw/fork_call/;
my $cond = AnyEvent->condvar;
my $timer = AnyEvent->timer(
interval => 3,
cb => sub {
say 'timer fired! '.time;
},
);
my $timer1 = AnyEvent->timer(
interval => 5,
cb => sub { fork_call {
my $start = time;
sleep 10;
my $end = time;
return 'counter done '.$start." - ".$end;
} sub {
say "bljad: " . join "", @_;
}
},
);
$cond->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment