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