RuntimeTicker

Struct RuntimeTicker 

Source
pub struct RuntimeTicker { /* private fields */ }

Implementations§

Source§

impl RuntimeTicker

Source

pub async fn tick<O, Fut>(&self, fut: Fut) -> ProcessOperation<O>
where Fut: Future<Output = O>,

Await fut and the control channel concurrently, returning whichever completes first.

Examples found in repository?
examples/dynamic_add.rs (line 45)
36    fn process_start(&self) -> ProcFuture<'_> {
37        let id = self.id;
38        let guard = self.guard.clone();
39
40        Box::pin(async move {
41            let ticker = guard.runtime_ticker().await;
42            let mut beat = interval(Duration::from_secs(1));
43
44            loop {
45                match ticker.tick(beat.tick()).await {
46                    ProcessOperation::Next(_) => println!("worker-{id}: heartbeat"),
47                    ProcessOperation::Control(RuntimeControlMessage::Reload) => {
48                        println!("worker-{id}: received *reload*")
49                    }
50                    ProcessOperation::Control(RuntimeControlMessage::Shutdown) => {
51                        println!("worker-{id}: shutting down");
52                        break;
53                    }
54                    // absorb any future control messages we don't explicitly handle
55                    ProcessOperation::Control(_) => continue,
56                }
57            }
58            Ok(())
59        })
60    }
More examples
Hide additional examples
examples/simple.rs (line 43)
34    fn process_start(&self) -> ProcFuture<'_> {
35        let id = self.id;
36        let guard = self.guard.clone();
37
38        Box::pin(async move {
39            let ticker = guard.runtime_ticker().await;
40            let mut tic = interval(Duration::from_secs(1));
41
42            loop {
43                match ticker.tick(tic.tick()).await {
44                    ProcessOperation::Next(_) => {
45                        println!("worker-{id}: heartbeat");
46                    }
47                    ProcessOperation::Control(RuntimeControlMessage::Reload) => {
48                        println!("worker-{id}: received *reload*");
49                    }
50                    ProcessOperation::Control(RuntimeControlMessage::Shutdown) => {
51                        println!("worker-{id}: shutting down");
52                        break;
53                    }
54                    // absorb any future control messages we don't explicitly handle
55                    ProcessOperation::Control(_) => continue,
56                }
57            }
58            Ok(())
59        })
60    }

Trait Implementations§

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