atomr_streams/
runnable.rs1use std::future::Future;
4
5use crate::source::Source;
6
7pub struct RunnableGraph<M> {
8 runner: Box<dyn FnOnce() -> futures::future::BoxFuture<'static, M> + Send + 'static>,
9}
10
11impl<M: Send + 'static> RunnableGraph<M> {
12 pub fn new<F, Fut>(f: F) -> Self
13 where
14 F: FnOnce() -> Fut + Send + 'static,
15 Fut: Future<Output = M> + Send + 'static,
16 {
17 use futures::FutureExt;
18 RunnableGraph { runner: Box::new(move || f().boxed()) }
19 }
20
21 pub async fn run(self) -> M {
22 (self.runner)().await
23 }
24}
25
26impl<T: Send + 'static> RunnableGraph<Vec<T>> {
27 pub fn to_seq(source: Source<T>) -> Self {
28 Self::new(move || crate::sink::Sink::collect(source))
29 }
30}