Skip to main content

Immediate

Struct Immediate 

Source
pub struct Immediate;
Expand description

Immediate execution strategy.

This strategy executes a given task immediately, and is primarily intended for testing and debugging purposes. No threading is involved, which makes it much easier to reason about execution order. Additionally, it can act as a baseline for comparison with worker-based strategies.

Warning: When channels are involved, this strategy might deadlock, i.e., when a task from a worker thread tries to send on a bounded channel that is full. In this case, make sure to either use unbounded channels, or actively drain the channel before sending on it.

§Examples

use zrx_executor::strategy::{Immediate, Strategy};

// Create strategy and submit task
let strategy = Immediate::default();
strategy.submit(Box::new(|| println!("Task")))?;

Implementations§

Source§

impl Immediate

Source

pub fn new() -> Self

Creates an immediate execution strategy.

§Examples
use zrx_executor::strategy::Immediate;

// Create strategy
let strategy = Immediate::new();

Trait Implementations§

Source§

impl Debug for Immediate

Source§

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

Formats the execution strategy for debugging.

Source§

impl Default for Immediate

Source§

fn default() -> Self

Creates an immediate execution strategy.

§Examples
use zrx_executor::strategy::Immediate;

// Create strategy
let strategy = Immediate::default();
Source§

impl Strategy for Immediate

Source§

fn submit(&self, task: Box<dyn Task>) -> Result

Submits a task.

This method immediately executes the given Task, so that it runs on the main thread, which is primarily intended for testing and debugging.

Note that tasks are intended to only run once, which is why they are consumed. If a task needs to be run multiple times, it must be wrapped in a closure that creates a new task each time. This allows for safe sharing of state between tasks.

§Errors

This method is infallible, and will always return Ok.

Errors

§Examples
use zrx_executor::strategy::{Immediate, Strategy};

// Create strategy and submit task
let strategy = Immediate::default();
strategy.submit(Box::new(|| println!("Task")))?;
Source§

fn num_workers(&self) -> usize

Returns the number of workers.

The number of usable workers is always 1 for this strategy, as tasks are immediately executed on the main thread when submitted.

§Examples
use zrx_executor::strategy::{Immediate, Strategy};

// Get number of workers
let strategy = Immediate::new();
assert_eq!(strategy.num_workers(), 1);
Source§

fn num_tasks_running(&self) -> usize

Returns the number of running tasks.

The number of running tasks is always 0 for this strategy, as tasks are immediately executed on the main thread when submitted.

§Examples
use zrx_executor::strategy::{Immediate, Strategy};

// Get number of running tasks
let strategy = Immediate::default();
assert_eq!(strategy.num_tasks_running(), 0);
Source§

fn num_tasks_pending(&self) -> usize

Returns the number of pending tasks.

The number of pending tasks is always 0 for this strategy, as tasks are immediately executed on the main thread when submitted.

§Examples
use zrx_executor::strategy::{Immediate, Strategy};

// Get number of pending tasks
let strategy = Immediate::default();
assert_eq!(strategy.num_tasks_pending(), 0);
Source§

fn capacity(&self) -> usize

Returns the capacity.

§Examples
use zrx_executor::strategy::{Immediate, Strategy};

// Get capacity
let strategy = Immediate::default();
assert_eq!(strategy.capacity(), 0);

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.