pub struct NetworkBuilder { /* private fields */ }
Expand description
A Builder with which the foundationDB network event loop can be created
The foundationDB Network event loop can only be run once.
use foundationdb::api::FdbApiBuilder;
let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
let guard = unsafe { network_builder.boot() };
// do some work with foundationDB
drop(guard);
Implementations§
Source§impl NetworkBuilder
impl NetworkBuilder
Sourcepub fn set_option(self, option: NetworkOption) -> FdbResult<Self>
pub fn set_option(self, option: NetworkOption) -> FdbResult<Self>
Set network options.
Sourcepub fn build(self) -> FdbResult<(NetworkRunner, NetworkWait)>
pub fn build(self) -> FdbResult<(NetworkRunner, NetworkWait)>
Finalizes the initialization of the Network and returns a way to run/wait/stop the FoundationDB run loop.
It’s not recommended to use this method directly, you probably want the boot()
method.
In order to start the network you have to:
- call the unsafe
NetworkRunner::run()
method, most likely in a dedicated thread - wait for the thread to start
NetworkWait::wait
In order for the sequence to be safe, you MUST as stated in the NetworkRunner::run()
method
ensure that NetworkStop::stop()
is called before the process exit.
Aborting the process is still safe.
§Example
use foundationdb::api::FdbApiBuilder;
let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
let (runner, cond) = network_builder.build().expect("fdb network runners");
let net_thread = std::thread::spawn(move || {
unsafe { runner.run() }.expect("failed to run");
});
// Wait for the foundationDB network thread to start
let fdb_network = cond.wait();
// do some work with foundationDB, if a panic occur you still **MUST** catch it and call
// fdb_network.stop();
// You **MUST** call fdb_network.stop() before the process exit
fdb_network.stop().expect("failed to stop network");
net_thread.join().expect("failed to join fdb thread");
Sourcepub unsafe fn boot(self) -> FdbResult<NetworkAutoStop>
pub unsafe fn boot(self) -> FdbResult<NetworkAutoStop>
Starts the FoundationDB run loop in a dedicated thread. This finish initializing the FoundationDB Client API and can only be called once per process.
§Returns
A NetworkAutoStop
handle which must be dropped before the program exits.
§Safety
You MUST ensure drop
is called on the returned object before the program exits.
This is not required if the program is aborted.
This method used to be safe in version 0.4
. But because drop
on the returned object
might not be called before the program exits, it was found unsafe.
§Panics
Panics if the dedicated thread cannot be spawned or the internal condition primitive is poisonned.
§Examples
use foundationdb::api::FdbApiBuilder;
let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
let network = unsafe { network_builder.boot() };
// do some interesting things with the API...
drop(network);
use foundationdb::api::FdbApiBuilder;
#[tokio::main]
async fn main() {
let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
let network = unsafe { network_builder.boot() };
// do some interesting things with the API...
drop(network);
}