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§
Traits§
- Subject
- The trait that these coordinate functions work with.
Functions§
- run_
and_ destroy - Perform
actioninsubject, destroying the subject before returning. - run_
and_ stop - Perform
actioninsubject. - run_
and_ stop_ if_ exists - Perform
actioninsubjectif it exists.