pub struct JobQueue<P: Ord + Send + Sync + 'static> { /* private fields */ }Expand description
implements a job queue that sends result of each job to a listener.
Implementations§
Source§impl<P: Ord + Send + Sync + 'static> JobQueue<P>
impl<P: Ord + Send + Sync + 'static> JobQueue<P>
Sourcepub async fn stop(self) -> Result<(), StopQueueError>
pub async fn stop(self) -> Result<(), StopQueueError>
stop the job-queue, and drop it.
this method sends a message to the spawned job-queue task to stop and then waits for it to complete.
Comparison with drop():
if JobQueue is dropped:
- the stop message will be sent, but any error is ignored.
- the spawned task is not awaited.
Sourcepub fn add_job(
&self,
job: impl Into<Box<dyn Job>>,
priority: P,
) -> Result<JobHandle, AddJobError>
pub fn add_job( &self, job: impl Into<Box<dyn Job>>, priority: P, ) -> Result<JobHandle, AddJobError>
adds job to job-queue (with interior mutability)
returns a JobHandle that can be used to await or cancel the job.
note that this method utilizes interior mutability. Consider calling
Self::add_job_mut() instead to make the mutation explicit.
Sourcepub fn add_job_mut(
&mut self,
job: impl Into<Box<dyn Job>>,
priority: P,
) -> Result<JobHandle, AddJobError>
pub fn add_job_mut( &mut self, job: impl Into<Box<dyn Job>>, priority: P, ) -> Result<JobHandle, AddJobError>
Adds a job to the queue (with explicit mutability).
returns a JobHandle that can be used to await or cancel the job.
job-results can be obtained by via JobHandle::results().await The job can be cancelled by JobHandle::cancel()
Unlike Self::add_job(), this method takes &mut self, explicitly
signaling to the compiler that the JobQueue internal state is being
modified.
This explicit mutability encourages callers to use correct function signatures and avoids hidden interior mutability, which can be a source of confusion and potentially subtle borrow checker issues when reasoning about a given codebase/architecture.
Explicit mutability generally leads to improved compiler optimizations and stronger borrow checker guarantees by enforcing exclusive access.
Sourcepub fn num_queued_jobs(&self) -> usize
pub fn num_queued_jobs(&self) -> usize
returns number of queued jobs