… | |
… | |
7 | |
7 | |
8 | =head1 SYNOPSIS |
8 | =head1 SYNOPSIS |
9 | |
9 | |
10 | use AnyEvent; |
10 | use AnyEvent; |
11 | |
11 | |
|
|
12 | # if you prefer function calls, look at the L<AE> manpage for |
|
|
13 | # an alternative API. |
|
|
14 | |
12 | # file descriptor readable |
15 | # file handle or descriptor readable |
13 | my $w = AnyEvent->io (fh => $fh, poll => "r", cb => sub { ... }); |
16 | my $w = AnyEvent->io (fh => $fh, poll => "r", cb => sub { ... }); |
14 | |
17 | |
15 | # one-shot or repeating timers |
18 | # one-shot or repeating timers |
16 | my $w = AnyEvent->timer (after => $seconds, cb => sub { ... }); |
19 | my $w = AnyEvent->timer (after => $seconds, cb => sub { ... }); |
17 | my $w = AnyEvent->timer (after => $seconds, interval => $seconds, cb => ... |
20 | my $w = AnyEvent->timer (after => $seconds, interval => $seconds, cb => ... |
… | |
… | |
1342 | |
1345 | |
1343 | =head1 SIMPLIFIED AE API |
1346 | =head1 SIMPLIFIED AE API |
1344 | |
1347 | |
1345 | Starting with version 5.0, AnyEvent officially supports a second, much |
1348 | Starting with version 5.0, AnyEvent officially supports a second, much |
1346 | simpler, API that is designed to reduce the calling, typing and memory |
1349 | simpler, API that is designed to reduce the calling, typing and memory |
1347 | overhead. |
1350 | overhead by using function call syntax and a fixed number of parameters. |
1348 | |
1351 | |
1349 | See the L<AE> manpage for details. |
1352 | See the L<AE> manpage for details. |
1350 | |
1353 | |
1351 | =cut |
1354 | =cut |
1352 | |
1355 | |
1353 | package AE; |
1356 | package AE; |
1354 | |
1357 | |
1355 | our $VERSION = $AnyEvent::VERSION; |
1358 | our $VERSION = $AnyEvent::VERSION; |
|
|
1359 | |
|
|
1360 | # fall back to the main API by default - backends and AnyEvent::Base |
|
|
1361 | # implementations can overwrite these. |
1356 | |
1362 | |
1357 | sub io($$$) { |
1363 | sub io($$$) { |
1358 | AnyEvent->io (fh => $_[0], poll => $_[1] ? "w" : "r", cb => $_[2]) |
1364 | AnyEvent->io (fh => $_[0], poll => $_[1] ? "w" : "r", cb => $_[2]) |
1359 | } |
1365 | } |
1360 | |
1366 | |
… | |
… | |
2075 | |
2081 | |
2076 | The actual code goes further and collects all errors (C<die>s, exceptions) |
2082 | The actual code goes further and collects all errors (C<die>s, exceptions) |
2077 | that occurred during request processing. The C<result> method detects |
2083 | that occurred during request processing. The C<result> method detects |
2078 | whether an exception as thrown (it is stored inside the $txn object) |
2084 | whether an exception as thrown (it is stored inside the $txn object) |
2079 | and just throws the exception, which means connection errors and other |
2085 | and just throws the exception, which means connection errors and other |
2080 | problems get reported tot he code that tries to use the result, not in a |
2086 | problems get reported to the code that tries to use the result, not in a |
2081 | random callback. |
2087 | random callback. |
2082 | |
2088 | |
2083 | All of this enables the following usage styles: |
2089 | All of this enables the following usage styles: |
2084 | |
2090 | |
2085 | 1. Blocking: |
2091 | 1. Blocking: |