roa_core/app/
runtime.rs

1use crate::executor::{BlockingObj, FutureObj};
2use crate::{App, Spawn};
3
4impl<S> App<S, ()> {
5    /// Construct app with default runtime.
6    #[cfg_attr(feature = "docs", doc(cfg(feature = "runtime")))]
7    #[inline]
8    pub fn state(state: S) -> Self {
9        Self::with_exec(state, Exec)
10    }
11}
12
13impl App<(), ()> {
14    /// Construct app with default runtime.
15    #[cfg_attr(feature = "docs", doc(cfg(feature = "runtime")))]
16    #[inline]
17    pub fn new() -> Self {
18        Self::state(())
19    }
20}
21
22impl Default for App<(), ()> {
23    /// Construct app with default runtime.
24    fn default() -> Self {
25        Self::new()
26    }
27}
28
29pub struct Exec;
30
31impl Spawn for Exec {
32    #[inline]
33    fn spawn(&self, fut: FutureObj) {
34        tokio::task::spawn(fut);
35    }
36
37    #[inline]
38    fn spawn_blocking(&self, task: BlockingObj) {
39        tokio::task::spawn_blocking(task);
40    }
41}