async_callback_manager/
lib.rs

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