pub struct RuntimeTicker { /* private fields */ }Implementations§
Source§impl RuntimeTicker
impl RuntimeTicker
Sourcepub async fn tick<O, Fut>(&self, fut: Fut) -> ProcessOperation<O>where
Fut: Future<Output = O>,
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
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§
impl Send for RuntimeTicker
impl Sync for RuntimeTicker
Auto Trait Implementations§
impl Freeze for RuntimeTicker
impl !RefUnwindSafe for RuntimeTicker
impl Unpin for RuntimeTicker
impl !UnwindSafe for RuntimeTicker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more