Skip to main content

dope_runtime/topology/
app.rs

1use std::time;
2
3use dope_core::driver::storage;
4
5use crate::{
6    executor::{self, session},
7    topology::lending,
8};
9
10/// Exact installed application paired with the session that owns its driver.
11pub struct Application<'scope, 'life: 'scope, 'p: 'life, 'd: 'p, S, A, Q: 'd>
12where
13    S: storage::Plan + 'd,
14{
15    pub(super) session: session::Scope<'scope, 'life, 'p, 'd, S, Q>,
16    pub(super) app: A,
17}
18
19impl<'scope, 'life: 'scope, 'p: 'life, 'd: 'p, S, A, Q> Application<'scope, 'life, 'p, 'd, S, A, Q>
20where
21    S: storage::Plan + 'd,
22    A: executor::raw::App<'d>,
23    Q: executor::Startup + 'd,
24{
25    /// Closes the installed application through its owning session.
26    pub fn finish<'report>(
27        self,
28        report: &'report mut session::Completion,
29    ) -> Result<(), session::Error<'report, ()>> {
30        self.session.finish(report, self.app)
31    }
32
33    pub fn with_app<'report, R>(
34        mut self,
35        report: &'report mut session::Completion,
36        run: impl for<'app> FnOnce(session::App<'app, 'life, 'd, A, Q>) -> R,
37    ) -> session::Result<'report, R> {
38        self.session.with_app(report, self.app, run)
39    }
40
41    pub fn with_lent<'report, B>(
42        mut self,
43        report: &'report mut session::Completion,
44        build: B,
45    ) -> lending::Result<'report, B::Error, B::Output>
46    where
47        A: lending::Root<'d> + lending::raw::Resume<'d>,
48        B: lending::Execute<'life, 'd, A, Q>,
49    {
50        lending::Stage::new(&mut self.session).with_lent(report, self.app, build)
51    }
52
53    pub fn with_quiesce<'report, R>(
54        mut self,
55        report: &'report mut session::Completion,
56        timeout: time::Duration,
57        run: impl for<'app> FnOnce(session::App<'app, 'life, 'd, A, Q>) -> R,
58    ) -> session::Result<'report, R> {
59        self.session.with_quiesce(report, self.app, timeout, run)
60    }
61}