pub trait ExecutorService: Send + Sync {
type Handle<R: Send + 'static, E: Send + 'static>;
type Termination<'a>: Future<Output = ()> + Send + 'a
where Self: 'a;
// Required methods
fn submit_callable<C, R, E>(
&self,
task: C,
) -> Result<Self::Handle<R, E>, RejectedExecution>
where C: Callable<R, E> + Send + 'static,
R: Send + 'static,
E: Send + 'static;
fn shutdown(&self);
fn shutdown_now(&self) -> ShutdownReport;
fn is_shutdown(&self) -> bool;
fn is_terminated(&self) -> bool;
fn await_termination(&self) -> Self::Termination<'_>;
// Provided method
fn submit<T, E>(
&self,
task: T,
) -> Result<Self::Handle<(), E>, RejectedExecution>
where T: Runnable<E> + Send + 'static,
E: Send + 'static { ... }
}Expand description
Managed task service with submission and lifecycle control.
ExecutorService is intentionally separate from
Executor. An executor describes an
execution strategy; an executor service accepts tasks into a managed service
that may queue, schedule, assign workers, and track lifecycle.
submit and submit_callable return Result values whose outer Ok
means only that the service accepted the task. It does not mean the task
has started or succeeded. The task’s final result is observed through the
returned handle.
Required Associated Types§
Sourcetype Termination<'a>: Future<Output = ()> + Send + 'a
where
Self: 'a
type Termination<'a>: Future<Output = ()> + Send + 'a where Self: 'a
Future returned when waiting for service termination.
Required Methods§
Sourcefn submit_callable<C, R, E>(
&self,
task: C,
) -> Result<Self::Handle<R, E>, RejectedExecution>
fn submit_callable<C, R, E>( &self, task: C, ) -> Result<Self::Handle<R, E>, RejectedExecution>
Submits a callable task to this service.
§Parameters
task- A fallible computation whose success value should be captured in the returned handle.
§Returns
Ok(handle) if the service accepts the task. This only reports
acceptance; task success, task failure, panic, or cancellation must be
observed through the returned handle. Returns Err(RejectedExecution) if
the service refuses the task before accepting it.
§Errors
Returns RejectedExecution when the service refuses the task before
accepting it.
Sourcefn shutdown(&self)
fn shutdown(&self)
Initiates an orderly shutdown.
After shutdown starts, new tasks are rejected. Already accepted tasks are allowed to complete unless the concrete service documents stronger cancellation behavior.
Sourcefn shutdown_now(&self) -> ShutdownReport
fn shutdown_now(&self) -> ShutdownReport
Attempts to stop accepting and running tasks immediately.
§Returns
A count-based shutdown report describing the state observed at the time of the request.
Sourcefn is_shutdown(&self) -> bool
fn is_shutdown(&self) -> bool
Returns whether shutdown has been requested.
§Returns
true if this service is no longer accepting new tasks.
Sourcefn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns whether the service has terminated.
§Returns
true only after shutdown has been requested and all accepted tasks have
completed or been cancelled.
Sourcefn await_termination(&self) -> Self::Termination<'_>
fn await_termination(&self) -> Self::Termination<'_>
Waits until the service has terminated.
§Returns
A future that completes after shutdown has been requested and no accepted tasks remain active.
Provided Methods§
Sourcefn submit<T, E>(
&self,
task: T,
) -> Result<Self::Handle<(), E>, RejectedExecution>
fn submit<T, E>( &self, task: T, ) -> Result<Self::Handle<(), E>, RejectedExecution>
Submits a runnable task to this service.
§Parameters
task- A fallible background action with no business return value.
§Returns
Ok(handle) if the service accepts the task. This only reports
acceptance; it does not report task start or task success. Returns
Err(RejectedExecution) if the service refuses the task before
accepting it.
§Errors
Returns RejectedExecution when the service refuses the task before
accepting it.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.