Skip to main content

JobQueue

Struct JobQueue 

Source
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>

Source

pub fn start() -> Self

creates job queue and starts it processing.

returns immediately.

Source

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:

  1. the stop message will be sent, but any error is ignored.
  2. the spawned task is not awaited.
Source

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.

Source

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.

Source

pub fn num_jobs(&self) -> usize

returns total number of jobs, queued plus running.

Source

pub fn num_queued_jobs(&self) -> usize

returns number of queued jobs

Trait Implementations§

Source§

impl<P: Debug + Ord + Send + Sync + 'static> Debug for JobQueue<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: Ord + Send + Sync + 'static> Drop for JobQueue<P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<P> Freeze for JobQueue<P>

§

impl<P> RefUnwindSafe for JobQueue<P>

§

impl<P> Send for JobQueue<P>

§

impl<P> Sync for JobQueue<P>

§

impl<P> Unpin for JobQueue<P>

§

impl<P> UnsafeUnpin for JobQueue<P>

§

impl<P> UnwindSafe for JobQueue<P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more