async_callback_manager/
lib.rs

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