dope_runtime/executor/session/
app.rs1use std::{ops, time};
2
3use o3::base::time::Positive;
4
5use crate::{
6 executor::{
7 self, drain,
8 drive::{self, clock},
9 root, session,
10 },
11 shutdown,
12};
13
14#[repr(transparent)]
16pub struct App<'app, 'life: 'app, 'd: 'life, D: executor::raw::Layout<'d>, Q = ()> {
17 pub(super) access: session::access::Access<'app, 'life, 'd, D, Q>,
18}
19
20impl<'app, 'life: 'app, 'd: 'life, D, Q> App<'app, 'life, 'd, D, Q>
21where
22 D: executor::raw::App<'d>,
23{
24 pub fn drive<R>(&mut self, root: R) -> Result<R::Output, drive::Error>
25 where
26 R: root::Root<'d>,
27 {
28 self.access
29 .reborrow()
30 .drive(clock::wall(), root, drive::tick)
31 }
32
33 pub fn run(self) -> Result<shutdown::Requested<Q>, drive::Error> {
34 self.access.run()?;
35 Ok(shutdown::Requested::new())
36 }
37
38 pub fn drive_for<R>(
41 &mut self,
42 timeout: time::Duration,
43 root: R,
44 ) -> Result<R::Output, drive::Error>
45 where
46 R: root::Root<'d>,
47 {
48 let source = clock::Bound::until(clock::wall(), timeout)?;
49 self.access.reborrow().drive(source, root, drive::timeout)
50 }
51
52 pub fn run_for(self, timeout: time::Duration) -> Result<shutdown::Requested<Q>, drive::Error> {
55 self.access.run_for(timeout)?;
56 Ok(shutdown::Requested::new())
57 }
58
59 pub fn run_drain(self, timeout: Positive) -> Result<drain::Report<Q>, drive::Error>
60 where
61 D: executor::raw::Drain<'d>,
62 {
63 let outcome = self.access.run_drain(timeout)?;
64 Ok(drain::Report::new(shutdown::Requested::new(), outcome))
65 }
66
67 pub fn drive_drain<R>(
70 self,
71 timeout: Positive,
72 root: R,
73 ) -> Result<ops::ControlFlow<R::Output, drain::Report<Q>>, drive::Error>
74 where
75 D: executor::raw::Drain<'d>,
76 R: root::Root<'d>,
77 {
78 Ok(self
79 .access
80 .drive_drain(timeout, root)?
81 .map_continue(|outcome| drain::Report::new(shutdown::Requested::new(), outcome)))
82 }
83}
84
85impl<'app, 'life: 'app, 'd: 'life, D, Q> ops::Deref for App<'app, 'life, 'd, D, Q>
86where
87 D: executor::raw::Layout<'d>,
88{
89 type Target = session::access::Access<'app, 'life, 'd, D, Q>;
90
91 fn deref(&self) -> &Self::Target {
92 &self.access
93 }
94}
95
96impl<'d, D: executor::raw::Layout<'d>, Q> ops::DerefMut for App<'_, '_, 'd, D, Q> {
97 fn deref_mut(&mut self) -> &mut Self::Target {
98 &mut self.access
99 }
100}