use super::{Configuration, Task};
use crate::observer::ObserverNotified;
use std::any::Any;
use std::future::Future;
use std::pin::Pin;
pub type BoxedSendFuture =
Pin<Box<dyn Future<Output = Box<dyn Any + 'static + Send>> + 'static + Send>>;
pub type BoxedSendObserverNotifier = Box<dyn ObserverNotified<dyn Any + Send> + Send>;
pub type ObjSafeTask = Task<BoxedSendFuture, BoxedSendObserverNotifier>;
pub type BoxedLocalFuture = Pin<Box<dyn Future<Output = Box<dyn Any + 'static>> + 'static>>;
pub type BoxedLocalObserverNotifier = Box<dyn ObserverNotified<dyn Any + 'static>>;
pub type ObjSafeLocalTask = Task<BoxedLocalFuture, BoxedLocalObserverNotifier>;
pub type ObjSafeStaticTask = Task<BoxedLocalFuture, BoxedLocalObserverNotifier>;
impl Task<BoxedSendFuture, BoxedSendObserverNotifier> {
pub fn new_objsafe(
label: String,
future: Box<dyn Future<Output = Box<dyn Any + Send + 'static>> + Send + 'static>,
configuration: Configuration,
notifier: Option<Box<dyn ObserverNotified<dyn Any + Send> + Send>>,
) -> Self {
Self::with_notifications(label, configuration, notifier, Box::into_pin(future))
}
}
impl Task<BoxedLocalFuture, BoxedLocalObserverNotifier> {
pub fn new_objsafe_local(
label: String,
future: Box<dyn Future<Output = Box<dyn Any + 'static>> + 'static>,
configuration: Configuration,
notifier: Option<Box<dyn ObserverNotified<dyn Any + 'static>>>,
) -> Self {
Self::with_notifications(label, configuration, notifier, Box::into_pin(future))
}
pub fn new_objsafe_static(
label: String,
future: Box<dyn Future<Output = Box<dyn Any + 'static>> + 'static>,
configuration: Configuration,
notifier: Option<Box<dyn ObserverNotified<dyn Any + 'static>>>,
) -> Self {
Self::with_notifications(label, configuration, notifier, Box::into_pin(future))
}
}