Crate marid [−] [src]
Marid
A process orchestration library.
This library is influenced by tedsuo's ifrit, a similar library for Golang.
The foundation of the library is built on the idea of a Runner
trait, which
encapsulates a singular unit of work, e.g. a thread, which is has a long lifetime, potentially
forever. The Process
is a trait that defines the actual running of one or more Runner
objects. Importantly, a Process
defines the ability to wait for, and signal a
Runner
.
Examples
use marid::{launch, Runner, Process, Composer, FnRunner, Signal}; let mut runner1 = Box::new(FnRunner::new(move |_sig| { // Do a bunch of work... Ok(()) })) as Box<Runner + Send>; let mut runner2 = Box::new(FnRunner::new(move |_sig| { // Do a bunch of other work... Ok(()) })) as Box<Runner + Send>; let composer = Composer::new(vec!(runner1, runner2), Signal::INT); let signals = vec!(Signal::INT, Signal::ALRM); // Start all Runners in separate threads. let process = launch(composer, signals); // Wait until all Runners have been setup. assert!(process.ready().is_ok()); // Send a shutdown signal to all Runners. process.signal(Signal::INT); // Wait until all Runners have finished. assert!(process.wait().is_ok());
Modules
test_helpers |
A testing module for Runner/Process traits. |
Structs
Composer |
The Composer type. |
MaridProcess |
Signifying the running state of a unit of work, a MaridProcess will spawn a new thread in order to not block the current thread. |
Receiver |
The receiving half of a channel. |
Sender |
The sending half of a channel. |
Enums
ProcessError |
Error type for a running Process. |
Signal |
The set of subscribable signals. |
Traits
Process |
A Process represents are running unit of work. It can be signaled and waited on. |
Runner |
A type implementing the Runner trait has the job of performing some arbitrary work while waiting for a signal indication shutdown. Upon receiving that defined shutdown Signal, the Runner must exit in a finite period of time. |
Functions
launch |
Launch the specified runner as well as listen on the specified signals. |
Type Definitions
FnRunner |
A Runner type that is constructed with a FnOnce closure. |
MaridError |
Error type for Marid Runners. |