use {
crate::AsContextMut,
anyhow::Result,
futures::{stream::FuturesUnordered, FutureExt},
std::{boxed::Box, future::Future, pin::Pin},
};
pub use futures_and_streams::{ErrorContext, FutureReader, StreamReader};
mod futures_and_streams;
pub struct Promise<T>(Pin<Box<dyn Future<Output = T> + Send + Sync + 'static>>);
impl<T: 'static> Promise<T> {
pub fn map<U>(self, fun: impl FnOnce(T) -> U + Send + Sync + 'static) -> Promise<U> {
Promise(Box::pin(self.0.map(fun)))
}
pub async fn get<U: Send>(self, store: impl AsContextMut<Data = U>) -> Result<T> {
_ = store;
todo!()
}
pub fn into_future(self) -> Pin<Box<dyn Future<Output = T> + Send + Sync + 'static>> {
self.0
}
}
pub struct PromisesUnordered<T>(
FuturesUnordered<Pin<Box<dyn Future<Output = T> + Send + Sync + 'static>>>,
);
impl<T: 'static> PromisesUnordered<T> {
pub fn new() -> Self {
Self(FuturesUnordered::new())
}
pub fn push(&mut self, promise: Promise<T>) {
self.0.push(promise.0)
}
pub async fn next<U: Send>(&mut self, store: impl AsContextMut<Data = U>) -> Result<Option<T>> {
_ = store;
todo!()
}
}