foundationdb::api

Function stop_network

Source
pub fn stop_network() -> FdbResult<()>
Expand description

Stops the FoundationDB network and joins the network thread.

This is terminal for the process: once it returns Ok, every FoundationDB operation fails with error 2025 (network_cannot_be_restarted), including in other threads. It is idempotent. One exception to terminality: if the client was never initialized at all (no boot, no API version selected, no Database created), the call is a plain no-op and a later boot still succeeds.

Tests and short-lived tools can simply rely on the automatic stop at process exit. In a production application, prefer calling this yourself as part of a clean shutdown sequence, once on-going operations are finished and the crate::Database handles are dropped.

Must not be called from the network thread itself (e.g. from a future callback), as it joins that thread.

ยงExamples

foundationdb::boot().expect("failed to initialize FoundationDB");
// ... use FoundationDB ...
foundationdb::api::stop_network().expect("failed to stop the network");
// The stop is terminal: any use of FoundationDB now fails with error 2025.
assert_eq!(foundationdb::boot().err().map(|e| e.code()), Some(2025));