ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.pm
(Generate patch)

Comparing BDB/BDB.pm (file contents):
Revision 1.49 by root, Thu Sep 25 13:30:14 2008 UTC vs.
Revision 1.50 by root, Thu Sep 25 22:09:02 2008 UTC

703 703
704You can still queue as many requests as you want. Therefore, 704You can still queue as many requests as you want. Therefore,
705C<max_oustsanding> is mainly useful in simple scripts (with low values) or 705C<max_oustsanding> is mainly useful in simple scripts (with low values) or
706as a stop gap to shield against fatal memory overflow (with large values). 706as a stop gap to shield against fatal memory overflow (with large values).
707 707
708=item BDB::set_sync_prepare $cb 708=item $old_cb = BDB::set_sync_prepare $cb
709 709
710Sets a callback that is called whenever a request is created without an 710Sets a callback that is called whenever a request is created without an
711explicit callback. It has to return two code references. The first is used 711explicit callback. It has to return two code references. The first is used
712as the request callback (it should save the return status), and the second 712as the request callback (it should save the return status), and the second
713is called to wait until the first callback has been called (it must set 713is called to wait until the first callback has been called (it must set
714C<$!> to the return status). 714C<$!> to the return status).
715 715
716This mechanism can be used to include BDB into other event mechanisms, 716This mechanism can be used to include BDB into other event mechanisms,
717such as L<AnyEvent::BDB> or L<Coro::BDB>. 717such as L<Coro::BDB>.
718 718
719The default implementation works like this: 719To allow other, callback-based, events to be executed while callback-less
720ones are run, you could use this sync prepare function:
720 721
721 sub { 722 sub {
722 my $status; 723 my $status;
723 ( 724 (
724 sub { $status = $! }, 725 sub { $status = $! },
725 sub { BDB::poll while !defined $status; $! = $status }, 726 sub { BDB::poll while !defined $status; $! = $status },
726 ) 727 )
727 } 728 }
728 729
729It simply blocks the process till the request has finished and then sets 730It works by polling for results till the request has finished and then
730C<$!> to the return value. This means that if you don't use a callback, 731sets C<$!> to the return value. This means that if you don't use a
731BDB will simply fall back to synchronous operations. 732callback, BDB would simply fall back to synchronous operations.
733
734By default, or if the sync prepare function is set to C<undef>, is to
735execute callback-less BDB requests in the foreground thread, setting C<$!>
736to the return value, without polling for other events.
732 737
733=back 738=back
734 739
735=head3 STATISTICAL INFORMATION 740=head3 STATISTICAL INFORMATION
736 741
758 763
759=back 764=back
760 765
761=cut 766=cut
762 767
763set_sync_prepare { 768set_sync_prepare (undef);
764 my $status;
765 (
766 sub {
767 $status = $!;
768 },
769 sub {
770 BDB::poll while !defined $status;
771 $! = $status;
772 },
773 )
774};
775 769
776min_parallel 8; 770min_parallel 8;
777 771
778END { flush } 772END { flush }
779 773

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines