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.156 by root, Fri Jun 6 10:23:50 2008 UTC vs.
Revision 1.164 by root, Tue Jul 8 19:50:25 2008 UTC

170 170
171Some event loops issue spurious readyness notifications, so you should 171Some event loops issue spurious readyness notifications, so you should
172always use non-blocking calls when reading/writing from/to your file 172always use non-blocking calls when reading/writing from/to your file
173handles. 173handles.
174 174
175Example:
176
177 # wait for readability of STDIN, then read a line and disable the watcher 175Example: wait for readability of STDIN, then read a line and disable the
176watcher.
177
178 my $w; $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub { 178 my $w; $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub {
179 chomp (my $input = <STDIN>); 179 chomp (my $input = <STDIN>);
180 warn "read: $input\n"; 180 warn "read: $input\n";
181 undef $w; 181 undef $w;
182 }); 182 });
192 192
193Although the callback might get passed parameters, their value and 193Although the callback might get passed parameters, their value and
194presence is undefined and you cannot rely on them. Portable AnyEvent 194presence is undefined and you cannot rely on them. Portable AnyEvent
195callbacks cannot use arguments passed to time watcher callbacks. 195callbacks cannot use arguments passed to time watcher callbacks.
196 196
197The timer callback will be invoked at most once: if you want a repeating 197The callback will normally be invoked once only. If you specify another
198timer you have to create a new watcher (this is a limitation by both Tk 198parameter, C<interval>, as a positive number, then the callback will be
199and Glib). 199invoked regularly at that interval (in fractional seconds) after the first
200invocation.
200 201
201Example: 202The callback will be rescheduled before invoking the callback, but no
203attempt is done to avoid timer drift in most backends, so the interval is
204only approximate.
202 205
203 # fire an event after 7.7 seconds 206Example: fire an event after 7.7 seconds.
207
204 my $w = AnyEvent->timer (after => 7.7, cb => sub { 208 my $w = AnyEvent->timer (after => 7.7, cb => sub {
205 warn "timeout\n"; 209 warn "timeout\n";
206 }); 210 });
207 211
208 # to cancel the timer: 212 # to cancel the timer:
209 undef $w; 213 undef $w;
210 214
211Example 2:
212
213 # fire an event after 0.5 seconds, then roughly every second 215Example 2: fire an event after 0.5 seconds, then roughly every second.
214 my $w;
215 216
216 my $cb = sub {
217 # cancel the old timer while creating a new one
218 $w = AnyEvent->timer (after => 1, cb => $cb); 217 my $w = AnyEvent->timer (after => 0.5, interval => 1, cb => sub {
218 warn "timeout\n";
219 }; 219 };
220
221 # start the "loop" by creating the first watcher
222 $w = AnyEvent->timer (after => 0.5, cb => $cb);
223 220
224=head3 TIMING ISSUES 221=head3 TIMING ISSUES
225 222
226There are two ways to handle timers: based on real time (relative, "fire 223There are two ways to handle timers: based on real time (relative, "fire
227in 10 seconds") and based on wallclock time (absolute, "fire at 12 224in 10 seconds") and based on wallclock time (absolute, "fire at 12
738=item L<AnyEvent::Util> 735=item L<AnyEvent::Util>
739 736
740Contains various utility functions that replace often-used but blocking 737Contains various utility functions that replace often-used but blocking
741functions such as C<inet_aton> by event-/callback-based versions. 738functions such as C<inet_aton> by event-/callback-based versions.
742 739
743=item L<AnyEvent::Handle>
744
745Provide read and write buffers and manages watchers for reads and writes.
746
747=item L<AnyEvent::Socket> 740=item L<AnyEvent::Socket>
748 741
749Provides various utility functions for (internet protocol) sockets, 742Provides various utility functions for (internet protocol) sockets,
750addresses and name resolution. Also functions to create non-blocking tcp 743addresses and name resolution. Also functions to create non-blocking tcp
751connections or tcp servers, with IPv6 and SRV record support and more. 744connections or tcp servers, with IPv6 and SRV record support and more.
752 745
746=item L<AnyEvent::Handle>
747
748Provide read and write buffers, manages watchers for reads and writes,
749supports raw and formatted I/O, I/O queued and fully transparent and
750non-blocking SSL/TLS.
751
753=item L<AnyEvent::DNS> 752=item L<AnyEvent::DNS>
754 753
755Provides rich asynchronous DNS resolver capabilities. 754Provides rich asynchronous DNS resolver capabilities.
756 755
757=item L<AnyEvent::HTTP> 756=item L<AnyEvent::HTTP>
765 764
766=item L<AnyEvent::FastPing> 765=item L<AnyEvent::FastPing>
767 766
768The fastest ping in the west. 767The fastest ping in the west.
769 768
769=item L<AnyEvent::DBI>
770
771Executes L<DBI> requests asynchronously in a proxy process.
772
773=item L<AnyEvent::AIO>
774
775Truly asynchronous I/O, should be in the toolbox of every event
776programmer. AnyEvent::AIO transparently fuses L<IO::AIO> and AnyEvent
777together.
778
779=item L<AnyEvent::BDB>
780
781Truly asynchronous Berkeley DB access. AnyEvent::BDB transparently fuses
782L<BDB> and AnyEvent together.
783
784=item L<AnyEvent::GPSD>
785
786A non-blocking interface to gpsd, a daemon delivering GPS information.
787
788=item L<AnyEvent::IGS>
789
790A non-blocking interface to the Internet Go Server protocol (used by
791L<App::IGS>).
792
770=item L<Net::IRC3> 793=item L<Net::IRC3>
771 794
772AnyEvent based IRC client module family. 795AnyEvent based IRC client module family.
773 796
774=item L<Net::XMPP2> 797=item L<Net::XMPP2>
786 809
787=item L<Coro> 810=item L<Coro>
788 811
789Has special support for AnyEvent via L<Coro::AnyEvent>. 812Has special support for AnyEvent via L<Coro::AnyEvent>.
790 813
791=item L<AnyEvent::AIO>, L<IO::AIO>
792
793Truly asynchronous I/O, should be in the toolbox of every event
794programmer. AnyEvent::AIO transparently fuses IO::AIO and AnyEvent
795together.
796
797=item L<AnyEvent::BDB>, L<BDB>
798
799Truly asynchronous Berkeley DB access. AnyEvent::AIO transparently fuses
800IO::AIO and AnyEvent together.
801
802=item L<IO::Lambda> 814=item L<IO::Lambda>
803 815
804The lambda approach to I/O - don't ask, look there. Can use AnyEvent. 816The lambda approach to I/O - don't ask, look there. Can use AnyEvent.
805 817
806=back 818=back
812no warnings; 824no warnings;
813use strict; 825use strict;
814 826
815use Carp; 827use Carp;
816 828
817our $VERSION = 4.14; 829our $VERSION = 4.2;
818our $MODEL; 830our $MODEL;
819 831
820our $AUTOLOAD; 832our $AUTOLOAD;
821our @ISA; 833our @ISA;
822 834
984sub AnyEvent::Base::Signal::DESTROY { 996sub AnyEvent::Base::Signal::DESTROY {
985 my ($signal, $cb) = @{$_[0]}; 997 my ($signal, $cb) = @{$_[0]};
986 998
987 delete $SIG_CB{$signal}{$cb}; 999 delete $SIG_CB{$signal}{$cb};
988 1000
989 $SIG{$signal} = 'DEFAULT' unless keys %{ $SIG_CB{$signal} }; 1001 delete $SIG{$signal} unless keys %{ $SIG_CB{$signal} };
990} 1002}
991 1003
992# default implementation for ->child 1004# default implementation for ->child
993 1005
994our %PID_CB; 1006our %PID_CB;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines