use crate::{
RuntimeError,
core::{TaskOutcome, deferred_drop::OwnedTask},
events::RejectionKind,
};
use super::super::{Controller, state::PendingSubmission};
pub(in crate::controller::engine) type StartFailure = Box<crate::core::UncommittedWatchedAdd>;
impl Controller {
pub(in crate::controller::engine) fn drop_pending_submissions(
&self,
pending: Vec<(StartFailure, Option<TaskOutcome>)>,
) {
for (pending, terminal) in pending {
self.drop_start_failure(pending, terminal);
}
}
pub(in crate::controller::engine) fn dispose_owned_task<T>(
&self,
owned: OwnedTask<T>,
terminal: Option<TaskOutcome>,
) where
T: Send + 'static,
{
let (value, mut cleanup) = owned.into_parts();
drop(value);
if let Some(terminal) = terminal {
cleanup.attach_outcome(terminal);
}
cleanup.submit();
}
pub(in crate::controller::engine) fn drop_pending_submission(
&self,
pending: PendingSubmission,
terminal: Option<TaskOutcome>,
) {
let PendingSubmission { owned, .. } = pending;
self.dispose_owned_task(owned, terminal);
}
pub(super) fn drop_start_failure(&self, pending: StartFailure, terminal: Option<TaskOutcome>) {
let crate::core::UncommittedWatchedAdd {
error,
label,
owned,
done,
} = *pending;
debug_assert!(done.is_none(), "the watcher must be restored before drop");
drop((error, label, done));
self.dispose_owned_task(owned, terminal);
}
pub(super) fn rejection_kind_for_runtime_error(error: &RuntimeError) -> RejectionKind {
if matches!(error, RuntimeError::ResourceLimitReached { .. }) {
RejectionKind::ResourceLimit
} else {
RejectionKind::AdmissionFailed
}
}
}