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.162 by root, Thu Jul 3 02:03:33 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>
767 766
768The fastest ping in the west. 767The fastest ping in the west.
769 768
770=item L<AnyEvent::DBI> 769=item L<AnyEvent::DBI>
771 770
772Executes DBI requests asynchronously in a proxy process. 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>).
773 792
774=item L<Net::IRC3> 793=item L<Net::IRC3>
775 794
776AnyEvent based IRC client module family. 795AnyEvent based IRC client module family.
777 796
790 809
791=item L<Coro> 810=item L<Coro>
792 811
793Has special support for AnyEvent via L<Coro::AnyEvent>. 812Has special support for AnyEvent via L<Coro::AnyEvent>.
794 813
795=item L<AnyEvent::AIO>, L<IO::AIO>
796
797Truly asynchronous I/O, should be in the toolbox of every event
798programmer. AnyEvent::AIO transparently fuses IO::AIO and AnyEvent
799together.
800
801=item L<AnyEvent::BDB>, L<BDB>
802
803Truly asynchronous Berkeley DB access. AnyEvent::AIO transparently fuses
804IO::AIO and AnyEvent together.
805
806=item L<IO::Lambda> 814=item L<IO::Lambda>
807 815
808The 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.
809 817
810=back 818=back
816no warnings; 824no warnings;
817use strict; 825use strict;
818 826
819use Carp; 827use Carp;
820 828
821our $VERSION = 4.160; 829our $VERSION = 4.2;
822our $MODEL; 830our $MODEL;
823 831
824our $AUTOLOAD; 832our $AUTOLOAD;
825our @ISA; 833our @ISA;
826 834

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines