Struct foundationdb::network::Network
source · pub struct Network(_);
Expand description
The FoundationDB client library performs most tasks on a singleton thread (which usually will be a different thread than your application runs on).
These functions are used to configure, start and stop the FoundationDB event loop on this thread.
NOTE Networks may only be constructed from an initalized fdb_api::FdbApi
Implementations§
source§impl Network
impl Network
sourcepub fn run(&self) -> Result<(), Error>
pub fn run(&self) -> Result<(), Error>
Must be called before any asynchronous functions in this API can be expected to complete.
Unless your program is entirely event-driven based on results of asynchronous functions in this API and has no event loop of its own, you will want to invoke this function on an auxiliary thread (which it is your responsibility to create).
This function will not return until Network::stop
is called by you or a serious error occurs. You must not invoke run
concurrently or reentrantly while it is already running.
sourcepub fn stop(&self) -> Result<(), Error>
pub fn stop(&self) -> Result<(), Error>
Signals the event loop invoked by Network::run
to terminate.
You must call this function and wait for fdb_run_network() to return before allowing your program to exit, or else the behavior is undefined.
Example
use std::thread;
use foundationdb;
let network = foundationdb::init().expect("failed to initialize Fdb");
let handle = std::thread::spawn(move || {
let error = network.run();
if let Err(error) = error {
panic!("fdb_run_network: {}", error);
}
});
network.wait();
// do some interesting things with the API...
network.stop().expect("failed to stop network");
handle.join().expect("failed to join fdb thread");