use crate::control::ControlHandle;
use crate::definitions::*;
use pi_result::RawResult as Result;
use crate::join::{JoinHandle, LocalOutput, OutputMode, SendOutput};
use crate::task::{Schedule, TaskOptions, TaskRef, TaskRegistration, TaskThread};
use std::future::Future;
#[must_use = "须执行、移交或按明确退出责任释放可执行句柄"]
pub struct Runnable {
pub(crate) task: TaskRef,
}
#[must_use = "创建与提交/执行分离;须处理本份可执行持有"]
pub struct TaskParts<T, M: Send + Sync + 'static = (), K: OutputMode = SendOutput> {
pub runnable: Runnable,
pub control: ControlHandle,
pub join: JoinHandle<T, M, K>,
}
pub struct BuildError<F, S, M> {
pub future: F,
pub schedule: S,
pub metadata: M,
pub options: TaskOptions,
pub cause: BuildErrorKind,
}
pub struct RunError {
pub runnable: Runnable,
pub cause: RunErrorKind,
}
impl Runnable {
pub fn id(&self) -> TaskId {
runnable_id_inner(self)
}
}
impl Runnable {
pub fn admit(&self, owner: &TaskThread) -> Result<TaskRegistration, AdmissionError> {
runnable_admit_inner(self, owner)
}
}
impl Runnable {
pub fn run(self, owner: &TaskThread) -> Result<RunOutcome, RunError> {
runnable_run_inner(self, owner)
}
}
impl Runnable {
pub fn snapshot(&self) -> TaskSnapshot {
runnable_snapshot_inner(self)
}
}
impl Runnable {
pub fn metadata<M: Send + Sync + 'static>(&self) -> Option<&M> {
runnable_metadata_inner(self)
}
}
impl Drop for Runnable {
fn drop(&mut self) {
runnable_drop_inner(self)
}
}
pub fn create<F, S, M>(
future: F,
schedule: S,
metadata: M,
options: TaskOptions,
) -> Result<TaskParts<F::Output, M, SendOutput>, BuildError<F, S, M>>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
S: Schedule,
M: Send + Sync + 'static,
{
create_inner(future, schedule, metadata, options)
}
pub fn create_local<F, S, M>(
owner: &TaskThread,
future: F,
schedule: S,
metadata: M,
options: TaskOptions,
) -> Result<TaskParts<F::Output, M, LocalOutput>, BuildError<F, S, M>>
where
F: Future + 'static,
F::Output: 'static,
S: Schedule,
M: Send + Sync + 'static,
{
create_local_inner(owner, future, schedule, metadata, options)
}
include!("runnable_inner.rs");