Struct flurx::scheduler::Scheduler

source ·
pub struct Scheduler<'state, 'future, State> { /* private fields */ }

Implementations§

source§

impl<'state, 'future, State> Scheduler<'state, 'future, State>
where State: Clone + 'state + 'future, 'state: 'future,

source

pub const fn new() -> Scheduler<'state, 'future, State>

Creates the empty scheduler.

source

pub const fn not_exists_reactor(&self) -> bool

source

pub const fn exists_reactor(&self) -> bool

source

pub fn schedule<F, Fut>(&mut self, f: F)
where F: FnOnce(ReactiveTask<'state, State>) -> Fut, Fut: Future<Output = ()> + 'future,

Schedule the new [Reactor].

The reality [Reactor] is Future, it is polled once every time Scheduler::run is called.

§Examples
use flurx::prelude::*;

#[tokio::main]
async fn main(){
    let mut scheduler = Scheduler::<usize>::new();
    scheduler.schedule(|task|async move{
        // (1)
        task.will(wait::until(|state: usize|{
            state < 2
        })).await;
    });
    // state is 0, (1) returns [`Future::Pending`].
    scheduler.run(0).await;
    // state is 1, (1) returns [`Future::Pending`].
    scheduler.run(1).await;
    // state is 2, (1) returns [`Future::Ready(2)`].
    scheduler.run(2).await;
}
source

pub async fn run(&mut self, state: State)

Poll all registered Reactors once each.

Trait Implementations§

source§

impl<'state, 'future, State> Default for Scheduler<'state, 'future, State>
where State: Clone + 'state + 'future, 'state: 'future,

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'state, 'future, State> Freeze for Scheduler<'state, 'future, State>

§

impl<'state, 'future, State> !RefUnwindSafe for Scheduler<'state, 'future, State>

§

impl<'state, 'future, State> !Send for Scheduler<'state, 'future, State>

§

impl<'state, 'future, State> !Sync for Scheduler<'state, 'future, State>

§

impl<'state, 'future, State> Unpin for Scheduler<'state, 'future, State>
where State: Unpin,

§

impl<'state, 'future, State> !UnwindSafe for Scheduler<'state, 'future, State>

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.