springtime/
runner.rs

1//! Runners executing actual application logic.
2
3#[cfg(feature = "async")]
4use crate::future::BoxFuture;
5#[cfg(test)]
6use mockall::automock;
7use springtime_di::injectable;
8pub use springtime_di::instance_provider::ErrorPtr;
9
10#[cfg(feature = "threadsafe")]
11pub type ApplicationRunnerPtr = dyn ApplicationRunner + Send + Sync;
12
13#[cfg(not(feature = "threadsafe"))]
14pub type ApplicationRunnerPtr = dyn ApplicationRunner;
15
16/// Runs application logic. Runners are run by the [Application](crate::application::Application)
17/// and are discovered by the dependency injection framework. If the `async` feature is enabled,
18/// runners with the same priority are ran concurrently.
19#[injectable]
20#[cfg_attr(test, automock)]
21pub trait ApplicationRunner {
22    #[cfg(feature = "async")]
23    /// Runs any application code.
24    fn run(&self) -> BoxFuture<'_, Result<(), ErrorPtr>>;
25
26    #[cfg(not(feature = "async"))]
27    /// Runs any application code.
28    fn run(&self) -> Result<(), ErrorPtr>;
29
30    /// Returns the priority for this runner. Higher priorities get run first. Default 0.
31    fn priority(&self) -> i8 {
32        0
33    }
34}