ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Fork-RPC/t/02_async.t
Revision: 1.2
Committed: Sun Apr 28 14:34:40 2013 UTC (13 years, 4 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_2, rel-1_24, rel-1_21, rel-1_22, rel-1_23, HEAD
Changes since 1.1: +3 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 $| = 1;
2     print "1..10\n";
3    
4     use AnyEvent;
5 root 1.2 # explicit version on next line, as some cpan-testers test with the 0.1 version,
6     # ignoring dependencies, and this line will at least give a clear indication of that.
7     use AnyEvent::Fork 0.6; # we don't actually depend on it, this is for convenience
8 root 1.1 use AnyEvent::Fork::RPC;
9    
10     print "ok 1\n";
11    
12     my $done = AE::cv;
13    
14     my $rpc = AnyEvent::Fork
15     ->new
16     ->require ("AnyEvent::Fork::RPC::Async")
17     ->eval (do { local $/; <DATA> })
18     ->AnyEvent::Fork::RPC::run ("run",
19     async => 1,
20     on_error => sub { print "Bail out! $_[0]\n"; exit 1 },
21     on_event => sub { print "$_[0]\n" },
22     on_destroy => $done,
23     );
24    
25     print "ok 2\n";
26    
27     $rpc->(3, sub { print $_[0] });
28    
29     print "ok 3\n";
30    
31     undef $rpc;
32    
33     print "ok 4\n";
34    
35     $done->recv;
36    
37     print "ok 10\n";
38    
39     __DATA__
40    
41     use AnyEvent;
42    
43     sub run {
44     my ($done, $count) = @_;
45    
46     my $n;
47    
48     AnyEvent::Fork::RPC::event "ok 5";
49    
50     my $w; $w = AE::timer 0.1, 0.1, sub {
51     ++$n;
52    
53     AnyEvent::Fork::RPC::event "ok " . ($n + 5);
54    
55     if ($n == $count) {
56     undef $w;
57     $done->("ok " . ($n + 6) . "\n");
58     }
59     };
60     }