… | |
… | |
597 | You can still queue as many requests as you want. Therefore, |
597 | You can still queue as many requests as you want. Therefore, |
598 | "max_oustsanding" is mainly useful in simple scripts (with low |
598 | "max_oustsanding" is mainly useful in simple scripts (with low |
599 | values) or as a stop gap to shield against fatal memory overflow |
599 | values) or as a stop gap to shield against fatal memory overflow |
600 | (with large values). |
600 | (with large values). |
601 | |
601 | |
602 | BDB::set_sync_prepare $cb |
602 | $old_cb = BDB::set_sync_prepare $cb |
603 | Sets a callback that is called whenever a request is created without |
603 | Sets a callback that is called whenever a request is created without |
604 | an explicit callback. It has to return two code references. The |
604 | an explicit callback. It has to return two code references. The |
605 | first is used as the request callback (it should save the return |
605 | first is used as the request callback (it should save the return |
606 | status), and the second is called to wait until the first callback |
606 | status), and the second is called to wait until the first callback |
607 | has been called (it must set $! to the return status). |
607 | has been called (it must set $! to the return status). |
608 | |
608 | |
609 | This mechanism can be used to include BDB into other event |
609 | This mechanism can be used to include BDB into other event |
610 | mechanisms, such as AnyEvent::BDB or Coro::BDB. |
610 | mechanisms, such as Coro::BDB. |
611 | |
611 | |
612 | The default implementation works like this: |
612 | To allow other, callback-based, events to be executed while |
|
|
613 | callback-less ones are run, you could use this sync prepare |
|
|
614 | function: |
613 | |
615 | |
614 | sub { |
616 | sub { |
615 | my $status; |
617 | my $status; |
616 | ( |
618 | ( |
617 | sub { $status = $! }, |
619 | sub { $status = $! }, |
618 | sub { BDB::poll while !defined $status; $! = $status }, |
620 | sub { BDB::poll while !defined $status; $! = $status }, |
619 | ) |
621 | ) |
620 | } |
622 | } |
621 | |
623 | |
622 | It simply blocks the process till the request has finished and then |
624 | It works by polling for results till the request has finished and |
623 | sets $! to the return value. This means that if you don't use a |
625 | then sets $! to the return value. This means that if you don't use a |
624 | callback, BDB will simply fall back to synchronous operations. |
626 | callback, BDB would simply fall back to synchronous operations. |
|
|
627 | |
|
|
628 | By default, or if the sync prepare function is set to "undef", is to |
|
|
629 | execute callback-less BDB requests in the foreground thread, setting |
|
|
630 | $! to the return value, without polling for other events. |
625 | |
631 | |
626 | STATISTICAL INFORMATION |
632 | STATISTICAL INFORMATION |
627 | BDB::nreqs |
633 | BDB::nreqs |
628 | Returns the number of requests currently in the ready, execute or |
634 | Returns the number of requests currently in the ready, execute or |
629 | pending states (i.e. for which their callback has not been invoked |
635 | pending states (i.e. for which their callback has not been invoked |