lucidity_core/
lib.rs

1//! The `lucidity-core` crate.  Abstracts away core functionality, and functionality for build scripts.
2
3#![warn(rustdoc::broken_intra_doc_links, rust_2018_idioms, clippy::all, missing_docs)]
4
5use core::time::Duration;
6
7use lunatic::{ap::ProcessRef, AbstractProcess};
8
9pub use lunatic;
10pub use rand;
11pub use serde;
12
13/// A job is a process that can be spawned and shutdown.
14///
15/// This type is usually created with the [`lucidity::job`] macro on the async methods.
16pub struct Job<T>
17where
18    T: AbstractProcess,
19{
20    /// The process reference.
21    pub process: ProcessRef<T>,
22}
23
24impl<T> Drop for Job<T>
25where
26    T: AbstractProcess,
27{
28    fn drop(&mut self) {
29        loop {
30            if let Ok(r) = self.process.with_timeout(Duration::from_millis(100)).shutdown() {
31                break r;
32            }
33        }
34    }
35}