ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/04_condvar.t
Revision: 1.6
Committed: Thu Aug 18 17:58:53 2011 UTC (12 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-7_05, rel-7_07, rel-7_01, rel-7_02, rel-7_03, rel-7_08, rel-7_09, rel-7_16, rel-7_13, rel-7_11, rel-6_1, rel-6_11, rel-6_12, rel-6_13, rel-7_15, rel-7_14, rel-7_12, rel-6_02, rel-6_01, rel-7_0, rel-7_04, rel-6_14, HEAD
Changes since 1.5: +23 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 use AnyEvent;
2 root 1.4 BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} }
3 root 1.1
4 root 1.6 $| = 1; print "1..28\n";
5 root 1.3
6 root 1.1 print "ok 1\n";
7    
8     {
9     my $cv = AnyEvent->condvar;
10    
11     $cv->cb (sub {
12     print $_[0]->ready ? "" : "not ", "ok 4\n";
13    
14     my $x = $_[0]->recv;
15     print $x == 7 ? "" : "not ", "ok 5 # $x == 7\n";
16    
17     my @x = $_[0]->recv;
18     print $x[1] == 5 ? "" : "not ", "ok 6 # $x[1] == 5\n";
19    
20     my $y = $cv->recv;
21     print $y == 7 ? "" : "not ", "ok 7 # $x == 7\n";
22     });
23    
24     my $t = AnyEvent->timer (after => 0, cb => sub {
25     print "ok 3\n";
26     $cv->send (7, 5);
27     });
28    
29     print "ok 2\n";
30 root 1.5 $cv->recv;
31 root 1.1 print "ok 8\n";
32    
33     my @x = $cv->recv;
34     print $x[1] == 5 ? "" : "not ", "ok 9 # $x[1] == 5\n";
35     }
36    
37     {
38     my $cv = AnyEvent->condvar;
39    
40     $cv->cb (sub {
41     print $_[0]->ready ? "" : "not ", "ok 12\n";
42    
43     my $x = eval { $_[0]->recv };
44     print !defined $x ? "" : "not ", "ok 13\n";
45     print $@ =~ /^kill/ ? "" : "not ", "ok 14 # $@\n";
46     });
47    
48     my $t = AnyEvent->timer (after => 0, cb => sub {
49     print "ok 11\n";
50     $cv->croak ("kill");
51     print "ok 15\n";
52     $cv->send (8, 6, 4);
53     print "ok 16\n";
54     });
55    
56     print "ok 10\n";
57     my @x = eval { $cv->recv };
58     print !@x ? "" : "not ", "ok 17 # @x\n";
59     print $@ =~ /^kill / ? "" : "not ", "ok 18 # $@\n";
60     }
61    
62 root 1.2 {
63     my $cv = AnyEvent->condvar;
64    
65     print "ok 19\n";
66     my $t = AnyEvent->timer (after => 0, cb => $cv);
67    
68     print "ok 20\n";
69     $cv->recv;
70     print "ok 21\n";
71     }
72    
73 root 1.6 {
74     my $cv = AE::cv {
75     print +($_[0]->recv)[0] == 6 ? "" : "not ", "ok 27\n";
76     };
77    
78     print "ok 22\n";
79    
80     $cv->begin (sub {
81     print "ok 26\n";
82     $_[0](6);
83     });
84    
85     print "ok 23\n";
86     $cv->begin;
87     print "ok 24\n";
88     $cv->end;
89     print "ok 25\n";
90     $cv->end;
91    
92     print "ok 28\n";
93     }
94