1 |
=head1 NAME |
2 |
|
3 |
Coro::BDB - truly asynchronous bdb access |
4 |
|
5 |
=head1 SYNOPSIS |
6 |
|
7 |
use Coro::BDB; |
8 |
use BDB; |
9 |
|
10 |
# can now use any of the bdb requests |
11 |
|
12 |
=head1 DESCRIPTION |
13 |
|
14 |
This module is an L<AnyEvent> user, you need to make sure that you use and |
15 |
run a supported event loop. |
16 |
|
17 |
This module implements a thin wrapper around the L<BDB> module: Each BDB |
18 |
request that could block and doesn't get passed a callback will normally |
19 |
block all coroutines. after loading this module, this will no longer be |
20 |
the case (it provides a suitable sync prepare callback). |
21 |
|
22 |
It will also register an AnyEvent watcher as soon as AnyEvent chooses an |
23 |
event loop. |
24 |
|
25 |
The AnyEvent watcher can be disabled by executing C<undef |
26 |
$Coro::BDB::WATCHER>. Please notify the author of when and why you think |
27 |
this was necessary. |
28 |
|
29 |
This module does not export anything (unlike L<Coro::AIO>), as BDB already |
30 |
supports leaving out the callback. |
31 |
|
32 |
=over 4 |
33 |
|
34 |
=cut |
35 |
|
36 |
package Coro::BDB; |
37 |
|
38 |
no warnings; |
39 |
use strict; |
40 |
|
41 |
use BDB (); |
42 |
use AnyEvent::BDB (); |
43 |
|
44 |
use Coro (); |
45 |
use Coro::AnyEvent (); |
46 |
|
47 |
use base Exporter::; |
48 |
|
49 |
our $VERSION = 5.0; |
50 |
our $WATCHER; |
51 |
|
52 |
BDB::set_sync_prepare { |
53 |
my $status; |
54 |
my $current = $Coro::current; |
55 |
( |
56 |
sub { |
57 |
$status = $!; |
58 |
$current->ready; undef $current; |
59 |
}, |
60 |
sub { |
61 |
Coro::schedule while defined $current; |
62 |
$! = $status; |
63 |
}, |
64 |
) |
65 |
}; |
66 |
|
67 |
=back |
68 |
|
69 |
=head1 SEE ALSO |
70 |
|
71 |
L<BDB> of course. |
72 |
|
73 |
=head1 AUTHOR |
74 |
|
75 |
Marc Lehmann <schmorp@schmorp.de> |
76 |
http://home.schmorp.de/ |
77 |
|
78 |
=cut |
79 |
|
80 |
1 |