… | |
… | |
1228 | warn "read: $input\n"; # output what has been read |
1228 | warn "read: $input\n"; # output what has been read |
1229 | $cv->send if $input =~ /^q/i; # quit program if /^q/i |
1229 | $cv->send if $input =~ /^q/i; # quit program if /^q/i |
1230 | }, |
1230 | }, |
1231 | ); |
1231 | ); |
1232 | |
1232 | |
1233 | my $time_watcher; # can only be used once |
|
|
1234 | |
|
|
1235 | sub new_timer { |
|
|
1236 | $timer = AnyEvent->timer (after => 1, cb => sub { |
1233 | my $time_watcher = AnyEvent->timer (after => 1, interval => 1, cb => sub { |
1237 | warn "timeout\n"; # print 'timeout' about every second |
1234 | warn "timeout\n"; # print 'timeout' at most every second |
1238 | &new_timer; # and restart the time |
|
|
1239 | }); |
|
|
1240 | } |
1235 | }); |
1241 | |
|
|
1242 | new_timer; # create first timer |
|
|
1243 | |
1236 | |
1244 | $cv->recv; # wait until user enters /^q/i |
1237 | $cv->recv; # wait until user enters /^q/i |
1245 | |
1238 | |
1246 | REAL-WORLD EXAMPLE |
1239 | REAL-WORLD EXAMPLE |
1247 | Consider the Net::FCP module. It features (among others) the following |
1240 | Consider the Net::FCP module. It features (among others) the following |
… | |
… | |
1665 | As you can see, the AnyEvent + EV combination even beats the |
1658 | As you can see, the AnyEvent + EV combination even beats the |
1666 | hand-optimised "raw sockets benchmark", while AnyEvent + its pure perl |
1659 | hand-optimised "raw sockets benchmark", while AnyEvent + its pure perl |
1667 | backend easily beats IO::Lambda and POE. |
1660 | backend easily beats IO::Lambda and POE. |
1668 | |
1661 | |
1669 | And even the 100% non-blocking version written using the high-level (and |
1662 | And even the 100% non-blocking version written using the high-level (and |
1670 | slow :) AnyEvent::Handle abstraction beats both POE and IO::Lambda by a |
1663 | slow :) AnyEvent::Handle abstraction beats both POE and IO::Lambda |
1671 | large margin, even though it does all of DNS, tcp-connect and socket I/O |
1664 | higher level ("unoptimised") abstractions by a large margin, even though |
1672 | in a non-blocking way. |
1665 | it does all of DNS, tcp-connect and socket I/O in a non-blocking way. |
1673 | |
1666 | |
1674 | The two AnyEvent benchmarks programs can be found as eg/ae0.pl and |
1667 | The two AnyEvent benchmarks programs can be found as eg/ae0.pl and |
1675 | eg/ae2.pl in the AnyEvent distribution, the remaining benchmarks are |
1668 | eg/ae2.pl in the AnyEvent distribution, the remaining benchmarks are |
1676 | part of the IO::lambda distribution and were used without any changes. |
1669 | part of the IO::Lambda distribution and were used without any changes. |
1677 | |
1670 | |
1678 | SIGNALS |
1671 | SIGNALS |
1679 | AnyEvent currently installs handlers for these signals: |
1672 | AnyEvent currently installs handlers for these signals: |
1680 | |
1673 | |
1681 | SIGCHLD |
1674 | SIGCHLD |