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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.266 by root, Thu Jul 30 03:41:56 2009 UTC vs.
Revision 1.270 by root, Fri Jul 31 20:16:34 2009 UTC

399 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 }); 399 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 });
400 400
401=head3 Signal Races, Delays and Workarounds 401=head3 Signal Races, Delays and Workarounds
402 402
403Many event loops (e.g. Glib, Tk, Qt, IO::Async) do not support attaching 403Many event loops (e.g. Glib, Tk, Qt, IO::Async) do not support attaching
404callbacks to signals in a generic way, which is a pity, as you cannot do 404callbacks to signals in a generic way, which is a pity, as you cannot
405race-free signal handling in perl. AnyEvent will try to do it's best, but 405do race-free signal handling in perl, requiring C libraries for
406this. AnyEvent will try to do it's best, which means in some cases,
406in some cases, signals will be delayed. The maximum time a signal might 407signals will be delayed. The maximum time a signal might be delayed is
407be delayed is specified in C<$AnyEvent::MAX_SIGNAL_LATENCY> (default: 10 408specified in C<$AnyEvent::MAX_SIGNAL_LATENCY> (default: 10 seconds). This
408seconds). This variable can be changed only before the first signal 409variable can be changed only before the first signal watcher is created,
409watcher is created, and should be left alone otherwise. Higher values 410and should be left alone otherwise. This variable determines how often
411AnyEvent polls for signals (in case a wake-up was missed). Higher values
410will cause fewer spurious wake-ups, which is better for power and CPU 412will cause fewer spurious wake-ups, which is better for power and CPU
413saving.
414
411saving. All these problems can be avoided by installing the optional 415All these problems can be avoided by installing the optional
412L<Async::Interrupt> module. This will not work with inherently broken 416L<Async::Interrupt> module, which works with most event loops. It will not
413event loops such as L<Event> or L<Event::Lib> (and not with L<POE> 417work with inherently broken event loops such as L<Event> or L<Event::Lib>
414currently, as POE does it's own workaround with one-second latency). With 418(and not with L<POE> currently, as POE does it's own workaround with
415those, you just have to suffer the delays. 419one-second latency). For those, you just have to suffer the delays.
416 420
417=head2 CHILD PROCESS WATCHERS 421=head2 CHILD PROCESS WATCHERS
418 422
419 $w = AnyEvent->child (pid => <process id>, cb => <callback>); 423 $w = AnyEvent->child (pid => <process id>, cb => <callback>);
420 424
786=item $cb = $cv->cb ($cb->($cv)) 790=item $cb = $cv->cb ($cb->($cv))
787 791
788This is a mutator function that returns the callback set and optionally 792This is a mutator function that returns the callback set and optionally
789replaces it before doing so. 793replaces it before doing so.
790 794
791The callback will be called when the condition becomes "true", i.e. when 795The callback will be called when the condition becomes (or already was)
792C<send> or C<croak> are called, with the only argument being the condition 796"true", i.e. when C<send> or C<croak> are called (or were called), with
793variable itself. Calling C<recv> inside the callback or at any later time 797the only argument being the condition variable itself. Calling C<recv>
794is guaranteed not to block. 798inside the callback or at any later time is guaranteed not to block.
795 799
796=back 800=back
797 801
798=head1 SUPPORTED EVENT LOOPS/BACKENDS 802=head1 SUPPORTED EVENT LOOPS/BACKENDS
799 803
1111 1115
1112BEGIN { AnyEvent::common_sense } 1116BEGIN { AnyEvent::common_sense }
1113 1117
1114use Carp (); 1118use Carp ();
1115 1119
1116our $VERSION = 4.881; 1120our $VERSION = 4.9;
1117our $MODEL; 1121our $MODEL;
1118 1122
1119our $AUTOLOAD; 1123our $AUTOLOAD;
1120our @ISA; 1124our @ISA;
1121 1125
1630 Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak}; 1634 Carp::croak $_[0]{_ae_croak} if $_[0]{_ae_croak};
1631 wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0] 1635 wantarray ? @{ $_[0]{_ae_sent} } : $_[0]{_ae_sent}[0]
1632} 1636}
1633 1637
1634sub cb { 1638sub cb {
1635 $_[0]{_ae_cb} = $_[1] if @_ > 1; 1639 my $cv = shift;
1640
1641 @_
1642 and $cv->{_ae_cb} = shift
1643 and $cv->{_ae_sent}
1644 and (delete $cv->{_ae_cb})->($cv);
1645
1636 $_[0]{_ae_cb} 1646 $cv->{_ae_cb}
1637} 1647}
1638 1648
1639sub begin { 1649sub begin {
1640 ++$_[0]{_ae_counter}; 1650 ++$_[0]{_ae_counter};
1641 $_[0]{_ae_end_cb} = $_[1] if @_ > 1; 1651 $_[0]{_ae_end_cb} = $_[1] if @_ > 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines