pub struct RepeaterHandle<E>{ /* private fields */ }Expand description
Used to communicate with the repeater task
Returned after the call to Repeater::run_with_async_callback
Implementations§
Source§impl<E> RepeaterHandle<E>
impl<E> RepeaterHandle<E>
Sourcepub async fn insert(&self, e: E) -> Result<(), ConnectionLost>
pub async fn insert(&self, e: E) -> Result<(), ConnectionLost>
Insert entry into Repeater
Examples found in repository?
examples/simple.rs (line 44)
32async fn main() {
33 let callback = |entry, _| async move { println!("Popped {entry:?}") };
34
35 // create and start the repeater
36 let handle = async_repeater::Repeater::with_capacity(25).run_with_async_callback(callback);
37
38 // create entries with the same interval
39 let dur = Duration::from_secs(5);
40 let repetition = vec![Entry::new(0, dur), Entry::new(1, dur), Entry::new(2, dur)];
41
42 // insert the entries into the repeater with 1 second delay in between
43 for repetition in repetition {
44 handle.insert(repetition).await.unwrap();
45 tokio::time::sleep(Duration::from_secs(1)).await;
46 }
47
48 // wait for a ctrl-c.
49 // If this wasn't there, the program would exit immidiatly without running
50 // a single repetition
51 tokio::signal::ctrl_c().await.unwrap();
52 handle.stop().await.unwrap();
53 println!("Stopping cycler");
54}Sourcepub async fn remove(&self, key: E::Key) -> Result<(), ConnectionLost>
pub async fn remove(&self, key: E::Key) -> Result<(), ConnectionLost>
Remove entry from Repeater
Sourcepub async fn stop(self) -> Result<(), ConnectionLost>
pub async fn stop(self) -> Result<(), ConnectionLost>
Stop a Repeater
Examples found in repository?
examples/simple.rs (line 52)
32async fn main() {
33 let callback = |entry, _| async move { println!("Popped {entry:?}") };
34
35 // create and start the repeater
36 let handle = async_repeater::Repeater::with_capacity(25).run_with_async_callback(callback);
37
38 // create entries with the same interval
39 let dur = Duration::from_secs(5);
40 let repetition = vec![Entry::new(0, dur), Entry::new(1, dur), Entry::new(2, dur)];
41
42 // insert the entries into the repeater with 1 second delay in between
43 for repetition in repetition {
44 handle.insert(repetition).await.unwrap();
45 tokio::time::sleep(Duration::from_secs(1)).await;
46 }
47
48 // wait for a ctrl-c.
49 // If this wasn't there, the program would exit immidiatly without running
50 // a single repetition
51 tokio::signal::ctrl_c().await.unwrap();
52 handle.stop().await.unwrap();
53 println!("Stopping cycler");
54}Trait Implementations§
Source§impl<E> Clone for RepeaterHandle<E>
impl<E> Clone for RepeaterHandle<E>
Source§fn clone(&self) -> RepeaterHandle<E>
fn clone(&self) -> RepeaterHandle<E>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<E> Freeze for RepeaterHandle<E>
impl<E> RefUnwindSafe for RepeaterHandle<E>
impl<E> Send for RepeaterHandle<E>where
E: Send,
impl<E> Sync for RepeaterHandle<E>where
E: Send,
impl<E> Unpin for RepeaterHandle<E>
impl<E> UnsafeUnpin for RepeaterHandle<E>
impl<E> UnwindSafe for RepeaterHandle<E>
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