ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/README
(Generate patch)

Comparing AnyEvent/README (file contents):
Revision 1.24 by root, Thu May 29 03:46:04 2008 UTC vs.
Revision 1.25 by root, Tue Jun 3 09:02:46 2008 UTC

1=> NAME 1NAME
2 AnyEvent - provide framework for multiple event loops 2 AnyEvent - provide framework for multiple event loops
3 3
4 EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event 4 EV, Event, Glib, Tk, Perl, Event::Lib, Qt, POE - various supported event
5 loops 5 loops
6 6
16 }); 16 });
17 17
18 my $w = AnyEvent->condvar; # stores whether a condition was flagged 18 my $w = AnyEvent->condvar; # stores whether a condition was flagged
19 $w->send; # wake up current and all future recv's 19 $w->send; # wake up current and all future recv's
20 $w->recv; # enters "main loop" till $condvar gets ->send 20 $w->recv; # enters "main loop" till $condvar gets ->send
21
22INTRODUCTION/TUTORIAL
23 This manpage is mainly a reference manual. If you are interested in a
24 tutorial or some gentle introduction, have a look at the AnyEvent::Intro
25 manpage.
21 26
22WHY YOU SHOULD USE THIS MODULE (OR NOT) 27WHY YOU SHOULD USE THIS MODULE (OR NOT)
23 Glib, POE, IO::Async, Event... CPAN offers event models by the dozen 28 Glib, POE, IO::Async, Event... CPAN offers event models by the dozen
24 nowadays. So what is different about AnyEvent? 29 nowadays. So what is different about AnyEvent?
25 30
128 Many watchers either are used with "recursion" (repeating timers for 133 Many watchers either are used with "recursion" (repeating timers for
129 example), or need to refer to their watcher object in other ways. 134 example), or need to refer to their watcher object in other ways.
130 135
131 An any way to achieve that is this pattern: 136 An any way to achieve that is this pattern:
132 137
133 my $w; $w = AnyEvent->type (arg => value ..., cb => sub { 138 my $w; $w = AnyEvent->type (arg => value ..., cb => sub {
134 # you can use $w here, for example to undef it 139 # you can use $w here, for example to undef it
135 undef $w; 140 undef $w;
136 }); 141 });
137 142
138 Note that "my $w; $w =" combination. This is necessary because in Perl, 143 Note that "my $w; $w =" combination. This is necessary because in Perl,
139 my variables are only visible after the statement in which they are 144 my variables are only visible after the statement in which they are
140 declared. 145 declared.
141 146
337 an AnyEvent program, you *have* to create at least one watcher before 342 an AnyEvent program, you *have* to create at least one watcher before
338 you "fork" the child (alternatively, you can call "AnyEvent::detect"). 343 you "fork" the child (alternatively, you can call "AnyEvent::detect").
339 344
340 Example: fork a process and wait for it 345 Example: fork a process and wait for it
341 346
342 my $done = AnyEvent->condvar; 347 my $done = AnyEvent->condvar;
343 348
344 my $pid = fork or exit 5; 349 my $pid = fork or exit 5;
345 350
346 my $w = AnyEvent->child ( 351 my $w = AnyEvent->child (
347 pid => $pid, 352 pid => $pid,
348 cb => sub { 353 cb => sub {
349 my ($pid, $status) = @_; 354 my ($pid, $status) = @_;
350 warn "pid $pid exited with status $status"; 355 warn "pid $pid exited with status $status";
351 $done->send; 356 $done->send;
352 }, 357 },
353 ); 358 );
354 359
355 # do something else, then wait for process exit 360 # do something else, then wait for process exit
356 $done->recv; 361 $done->recv;
357 362
358 CONDITION VARIABLES 363 CONDITION VARIABLES
359 If you are familiar with some event loops you will know that all of them 364 If you are familiar with some event loops you will know that all of them
360 require you to run some blocking "loop", "run" or similar function that 365 require you to run some blocking "loop", "run" or similar function that
361 will actively watch for new events and call your callbacks. 366 will actively watch for new events and call your callbacks.
567 $cb = $cv->cb ([new callback]) 572 $cb = $cv->cb ([new callback])
568 This is a mutator function that returns the callback set and 573 This is a mutator function that returns the callback set and
569 optionally replaces it before doing so. 574 optionally replaces it before doing so.
570 575
571 The callback will be called when the condition becomes "true", i.e. 576 The callback will be called when the condition becomes "true", i.e.
572 when "send" or "croak" are called. Calling "recv" inside the 577 when "send" or "croak" are called, with the only argument being the
578 condition variable itself. Calling "recv" inside the callback or at
573 callback or at any later time is guaranteed not to block. 579 any later time is guaranteed not to block.
574 580
575GLOBAL VARIABLES AND FUNCTIONS 581GLOBAL VARIABLES AND FUNCTIONS
576 $AnyEvent::MODEL 582 $AnyEvent::MODEL
577 Contains "undef" until the first watcher is being created. Then it 583 Contains "undef" until the first watcher is being created. Then it
578 contains the event model that is being used, which is the name of 584 contains the event model that is being used, which is the name of
811 This functionality might change in future versions. 817 This functionality might change in future versions.
812 818
813 For example, to force the pure perl model (AnyEvent::Impl::Perl) you 819 For example, to force the pure perl model (AnyEvent::Impl::Perl) you
814 could start your program like this: 820 could start your program like this:
815 821
816 PERL_ANYEVENT_MODEL=Perl perl ... 822 PERL_ANYEVENT_MODEL=Perl perl ...
817 823
818 "PERL_ANYEVENT_PROTOCOLS" 824 "PERL_ANYEVENT_PROTOCOLS"
819 Used by both AnyEvent::DNS and AnyEvent::Socket to determine 825 Used by both AnyEvent::DNS and AnyEvent::Socket to determine
820 preferences for IPv4 or IPv6. The default is unspecified (and might 826 preferences for IPv4 or IPv6. The default is unspecified (and might
821 change, or be the result of auto probing). 827 change, or be the result of auto probing).
1262 model than specified in the variable. 1268 model than specified in the variable.
1263 1269
1264 You can make AnyEvent completely ignore this variable by deleting it 1270 You can make AnyEvent completely ignore this variable by deleting it
1265 before the first watcher gets created, e.g. with a "BEGIN" block: 1271 before the first watcher gets created, e.g. with a "BEGIN" block:
1266 1272
1267 BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} } 1273 BEGIN { delete $ENV{PERL_ANYEVENT_MODEL} }
1268 1274
1269 use AnyEvent; 1275 use AnyEvent;
1270 1276
1271 Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can 1277 Similar considerations apply to $ENV{PERL_ANYEVENT_VERBOSE}, as that can
1272 be used to probe what backend is used and gain other information (which 1278 be used to probe what backend is used and gain other information (which
1273 is probably even less useful to an attacker than PERL_ANYEVENT_MODEL). 1279 is probably even less useful to an attacker than PERL_ANYEVENT_MODEL).
1274 1280
1290 Coroutine support: Coro, Coro::AnyEvent, Coro::EV, Coro::Event, 1296 Coroutine support: Coro, Coro::AnyEvent, Coro::EV, Coro::Event,
1291 1297
1292 Nontrivial usage examples: Net::FCP, Net::XMPP2, AnyEvent::DNS. 1298 Nontrivial usage examples: Net::FCP, Net::XMPP2, AnyEvent::DNS.
1293 1299
1294AUTHOR 1300AUTHOR
1295 Marc Lehmann <schmorp@schmorp.de> 1301 Marc Lehmann <schmorp@schmorp.de>
1296 http://home.schmorp.de/ 1302 http://home.schmorp.de/
1297 1303

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines