Module coordinate

Module coordinate 

Source
Expand description

Safely coordinate use of things that can be controlled.

For example, if many concurrent processes want to make use of the same cluster, e.g. as part of a test suite, you can use run_and_stop to safely start and use the cluster, then stop it when it’s no longer needed:

let cluster_dir = tempfile::tempdir()?;
let data_dir = cluster_dir.path().join("data");
let strategy = runtime::strategy::Strategy::default();
let cluster = cluster::Cluster::new(&data_dir, strategy)?;
let lock_file = cluster_dir.path().join("lock");
let lock = lock::UnlockedFile::try_from(lock_file.as_path())?;
assert!(coordinate::run_and_stop(&cluster, &[], lock, || cluster::exists(&cluster))?);

Modules§

cleanup
finally
guard
resource
Manage a resource that can be started, stopped, and destroyed – i.e. a Subject – and which has different facets depending on whether it is locked exclusively, shared between multiple users, or unlocked/free.

Enums§

CoordinateError
State

Traits§

Subject
The trait that these coordinate functions work with.

Functions§

run_and_destroy
Perform action in subject, destroying the subject before returning.
run_and_stop
Perform action in subject.
run_and_stop_if_exists
Perform action in subject if it exists.