File: timer.t

package info (click to toggle)
libevent-perl 1.06-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 712 kB
  • ctags: 588
  • sloc: ansic: 3,020; perl: 1,128; makefile: 46
file content (56 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# the time for -*-perl-*-

use Test; plan tests => 7;
use Event qw(loop unloop);

# $Event::DebugLevel = 3;

#if (0) {

my $count = 0;
Event->timer(after => 0.5, interval => .1, nice => -1,
	     cb => sub { ++$count }, desc => "counter");

my $when = time + 2;
Event->timer(at => $when, cb => sub { ok $when, $_[0]->w->at; },
	     desc => "at");

my $again;
Event->timer(after => .5, cb => sub {
		 my $o=shift;
		 ok 1;
		 if (!$again) {
		     $again=1;
		     $o->w->again;
		     $o->w->again;  #should be harmless
		 }
	     }, desc => "after");

my $ok = Event->timer(interval => .5, cb => sub {
			  unloop('ok') if $count > 30
		      }, desc => "exit");
ok abs($ok->at - time) < 3, 1, "diff was ".($ok->at - time);

my $long;
for (1..10) {
    $long = Event->timer(after => 60+rand(60), cb => sub { ok 0; });
}
$long->cb(sub { ok 1 });
$long->at(time);

ok loop(), 'ok';

$_->cancel for Event::all_watchers();

#}

my $depth=0;
Event->timer(interval => .01, cb => sub {
		 if (++$depth < 2) {
		     loop();
		 } else {
		     Event::unloop_all('reentrant');
		 }
	     });

ok loop(), 'reentrant';