ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/event
(Generate patch)

Comparing Coro/eg/event (file contents):
Revision 1.8 by root, Fri Jul 27 02:51:33 2001 UTC vs.
Revision 1.11 by root, Sat Apr 14 15:06:06 2007 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2 2
3# this crap is an asynchroneous finger client. it's rather idiotic ;) 3# this crap is an asynchronous finger client. it's rather idiotic ;)
4 4
5use Coro; 5use Coro;
6use Coro::Event; 6use Coro::Event;
7use Coro::Socket; 7use Coro::Socket;
8 8
10sub finger { 10sub finger {
11 my $user = shift; 11 my $user = shift;
12 my $host = shift; 12 my $host = shift;
13 13
14 my $fh = new Coro::Socket PeerHost => $host, PeerPort => "finger" 14 my $fh = new Coro::Socket PeerHost => $host, PeerPort => "finger"
15 or die; 15 or die "$user\@$host: $!";
16 16
17 print $fh "$user\n"; 17 print $fh "$user\n";
18 18
19 print "$user\@$host: $_" while <$fh>; 19 print "$user\@$host: $_" while <$fh>;
20 print "$user\@$host: done\n"; 20 print "$user\@$host: done\n";
38 print "unknown command '$cmd', either 'finger' or 'quit'\n"; 38 print "unknown command '$cmd', either 'finger' or 'quit'\n";
39 } 39 }
40 } 40 }
41} 41}
42 42
43async { finger("root", "localhost") };
44
43# display the time or garble the display, YMMV. 45# display the time or garble the display, YMMV.
44sub timer : Coro { 46sub timer : Coro {
45 my $w = Coro::Event->timer(interval => 0.001, hard => 1); 47 my $w = Coro::Event->timer(interval => 0.001, hard => 1);
46 use Time::HiRes qw(time); 48 use Time::HiRes qw(time);
47 while () { 49 while () {
48 $w->next; 50 $w->next;
49 print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8"; 51 print "\e7\e[C\e[C\e[C\e[C\e[C\e[C\e[C\e[C <time ",time,"> \e8";
50 }; 52 };
51} 53}
52 54
55cede; # make sure the watchers are installed
53print "unlooped with value: ",loop(),"\n"; 56print "unlooped with value: ",loop(),"\n";
54 57

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines