Skip to main content

harmos_sdk/operations/
instance.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14pub use harmos_domain::operations::instance::*;
15
16/* === Imports === */
17
18// Standard Library Imports
19use std::future::Future;
20
21// Third Party Imports
22
23// Local Imports
24use super::{OperationDeclaration, Response};
25
26/* === Constants === */
27
28/* === Macros === */
29
30/* === Type Aliases === */
31
32/* === Structs === */
33
34/* === Enums === */
35
36/* === Traits === */
37
38// One submitted operation. Dropping an unsettled instance requests its
39// cancellation; `detach` hands the instance to the host and keeps it running.
40pub trait Instance<O: OperationDeclaration>: Send + Sized {
41    type Error: std::error::Error + Send + Sync + 'static;
42
43    fn id(&self) -> Id;
44
45    fn status(&self) -> impl Future<Output = Result<Status, Self::Error>> + Send;
46
47    fn cancel(&self) -> impl Future<Output = Result<(), Self::Error>> + Send;
48
49    fn join(self) -> impl Future<Output = Result<Response<O::Response>, Self::Error>> + Send;
50
51    fn cancel_and_join(self) -> impl Future<Output = Result<Response<O::Response>, Self::Error>> + Send {
52        async move {
53            self.cancel().await?;
54            self.join().await
55        }
56    }
57
58    fn detach(self) -> Id;
59}
60
61/* === Implementations === */
62
63/* === Public Functions === */
64
65/* === Private Functions === */
66
67/* === Tests === */