1 |
root |
1.1 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
Coro::BDB - truly asynchronous bdb access |
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS |
6 |
|
|
|
7 |
root |
1.8 |
use Coro::BDB; |
8 |
root |
1.1 |
use BDB; |
9 |
|
|
|
10 |
|
|
# can now use any of the bdb requests |
11 |
|
|
|
12 |
|
|
=head1 DESCRIPTION |
13 |
|
|
|
14 |
root |
1.5 |
This module is an L<AnyEvent> user, you need to make sure that you use and |
15 |
|
|
run a supported event loop. |
16 |
|
|
|
17 |
root |
1.7 |
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 |
root |
1.1 |
|
22 |
root |
1.7 |
It will also register an AnyEvent watcher as soon as AnyEvent chooses an |
23 |
root |
1.6 |
event loop. |
24 |
root |
1.1 |
|
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 |
root |
1.7 |
This module does not export anything (unlike L<Coro::AIO>), as BDB already |
30 |
root |
1.30 |
supports leaving out the callback. (Unfortunately, it ties a C context |
31 |
|
|
to each coroutine executing such a callback, so in the future, it might |
32 |
|
|
export more efficient wrappers). |
33 |
root |
1.7 |
|
34 |
root |
1.1 |
=over 4 |
35 |
|
|
|
36 |
|
|
=cut |
37 |
|
|
|
38 |
|
|
package Coro::BDB; |
39 |
|
|
|
40 |
|
|
no warnings; |
41 |
|
|
use strict; |
42 |
|
|
|
43 |
root |
1.20 |
use BDB (); |
44 |
|
|
use AnyEvent::BDB (); |
45 |
|
|
|
46 |
root |
1.1 |
use Coro (); |
47 |
root |
1.20 |
use Coro::AnyEvent (); |
48 |
root |
1.1 |
|
49 |
|
|
use base Exporter::; |
50 |
|
|
|
51 |
root |
1.38 |
our $VERSION = 5.151; |
52 |
root |
1.1 |
our $WATCHER; |
53 |
|
|
|
54 |
|
|
BDB::set_sync_prepare { |
55 |
root |
1.28 |
my $cb = Coro::rouse_cb; |
56 |
root |
1.1 |
( |
57 |
root |
1.28 |
sub { $cb->($!) }, |
58 |
|
|
sub { $! = Coro::rouse_wait }, |
59 |
root |
1.1 |
) |
60 |
|
|
}; |
61 |
|
|
|
62 |
|
|
=back |
63 |
|
|
|
64 |
|
|
=head1 SEE ALSO |
65 |
|
|
|
66 |
|
|
L<BDB> of course. |
67 |
|
|
|
68 |
|
|
=head1 AUTHOR |
69 |
|
|
|
70 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
71 |
|
|
http://home.schmorp.de/ |
72 |
|
|
|
73 |
|
|
=cut |
74 |
|
|
|
75 |
|
|
1 |