async_callback_manager/
lib.rs

1use futures::{Future, Stream};
2use std::any::Any;
3
4mod adaptors;
5mod error;
6mod manager;
7mod task;
8
9pub use adaptors::*;
10pub use error::*;
11pub use manager::*;
12pub use task::{AsyncTask, Constraint, TaskInformation, TaskOutcome};
13
14// Size of the channel used for each stream task.
15// In future, this could be settable.
16pub(crate) const DEFAULT_STREAM_CHANNEL_SIZE: usize = 20;
17
18pub trait BkendMap<Bkend> {
19    fn map(backend: &Bkend) -> &Self;
20}
21
22/// A task of kind T that can be run on a backend, returning a future of output
23/// Output. The type must implement Any, as the
24/// TypeId is used as part of the task management process.
25pub trait BackendTask<Bkend>: Send + Any {
26    type Output: Send;
27    type MetadataType: PartialEq;
28    fn into_future(self, backend: &Bkend) -> impl Future<Output = Self::Output> + Send + 'static;
29    /// Metadata provides a way of grouping different tasks for use in
30    /// constraints, if you override the default implementation.
31    fn metadata() -> Vec<Self::MetadataType> {
32        vec![]
33    }
34}
35
36/// A task of kind T that can be run on a backend, returning a stream of outputs
37/// Output. The type must implement Any, as the TypeId is used as part of the
38/// task management process.
39pub trait BackendStreamingTask<Bkend>: Send + Any {
40    type Output: Send;
41    type MetadataType: PartialEq;
42    fn into_stream(
43        self,
44        backend: &Bkend,
45    ) -> impl Stream<Item = Self::Output> + Send + Unpin + 'static;
46    /// Metadata provides a way of grouping different tasks for use in
47    /// constraints, if you override the default implementation.
48    fn metadata() -> Vec<Self::MetadataType> {
49        vec![]
50    }
51}