mm1_core/context/
fork.rs

1use std::future::Future;
2
3use mm1_common::errors::error_of::ErrorOf;
4use mm1_common::impl_error_kind;
5use mm1_proto::message;
6
7#[derive(Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8#[message]
9pub enum ForkErrorKind {
10    InternalError,
11    ResourceConstraint,
12}
13
14pub trait Fork: Sized + Send + 'static {
15    fn fork(&mut self) -> impl Future<Output = Result<Self, ErrorOf<ForkErrorKind>>> + Send;
16
17    fn run<F, Fut>(self, fun: F) -> impl Future<Output = ()> + Send
18    where
19        F: FnOnce(Self) -> Fut,
20        F: Send + 'static,
21        Fut: std::future::Future + Send + 'static;
22}
23
24impl_error_kind!(ForkErrorKind);