Struct tether_utils::tether_playback::TetherPlaybackUtil
source · pub struct TetherPlaybackUtil { /* private fields */ }Implementations§
source§impl TetherPlaybackUtil
impl TetherPlaybackUtil
sourcepub fn new(options: PlaybackOptions) -> Self
pub fn new(options: PlaybackOptions) -> Self
Examples found in repository?
examples/api.rs (line 81)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
fn demo_playback() {
let options = PlaybackOptions {
file_path: "./demo.json".into(),
override_topic: None,
loop_count: 1, // ignored anyway, in this case
loop_infinite: true,
ignore_ctrl_c: true, // this is important for programmatic use
};
let tether_agent = TetherAgentOptionsBuilder::new("demoTopics")
.build()
.expect("failed to init/connect Tether Agent");
let player = TetherPlaybackUtil::new(options);
let stop_request_tx = player.get_stop_tx();
let start_time = SystemTime::now();
let handles = vec![
spawn(move || {
player.start(&tether_agent);
}),
spawn(move || {
let mut time_to_end = false;
while !time_to_end {
if let Ok(elapsed) = start_time.elapsed() {
if elapsed > std::time::Duration::from_secs(3) {
println!("Time to stop! {}s elapsed", elapsed.as_secs());
stop_request_tx
.send(true)
.expect("failed to send stop request via channel");
time_to_end = true;
}
}
}
println!("Playback should have stopped now; wait 1 more seconds...");
std::thread::sleep(std::time::Duration::from_secs(1));
println!("...Bye");
}),
];
for handle in handles {
handle.join().expect("failed to join handle");
}
}sourcepub fn get_stop_tx(&self) -> Sender<bool>
pub fn get_stop_tx(&self) -> Sender<bool>
Examples found in repository?
examples/api.rs (line 82)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
fn demo_playback() {
let options = PlaybackOptions {
file_path: "./demo.json".into(),
override_topic: None,
loop_count: 1, // ignored anyway, in this case
loop_infinite: true,
ignore_ctrl_c: true, // this is important for programmatic use
};
let tether_agent = TetherAgentOptionsBuilder::new("demoTopics")
.build()
.expect("failed to init/connect Tether Agent");
let player = TetherPlaybackUtil::new(options);
let stop_request_tx = player.get_stop_tx();
let start_time = SystemTime::now();
let handles = vec![
spawn(move || {
player.start(&tether_agent);
}),
spawn(move || {
let mut time_to_end = false;
while !time_to_end {
if let Ok(elapsed) = start_time.elapsed() {
if elapsed > std::time::Duration::from_secs(3) {
println!("Time to stop! {}s elapsed", elapsed.as_secs());
stop_request_tx
.send(true)
.expect("failed to send stop request via channel");
time_to_end = true;
}
}
}
println!("Playback should have stopped now; wait 1 more seconds...");
std::thread::sleep(std::time::Duration::from_secs(1));
println!("...Bye");
}),
];
for handle in handles {
handle.join().expect("failed to join handle");
}
}sourcepub fn start(&self, tether_agent: &TetherAgent)
pub fn start(&self, tether_agent: &TetherAgent)
Examples found in repository?
examples/api.rs (line 88)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
fn demo_playback() {
let options = PlaybackOptions {
file_path: "./demo.json".into(),
override_topic: None,
loop_count: 1, // ignored anyway, in this case
loop_infinite: true,
ignore_ctrl_c: true, // this is important for programmatic use
};
let tether_agent = TetherAgentOptionsBuilder::new("demoTopics")
.build()
.expect("failed to init/connect Tether Agent");
let player = TetherPlaybackUtil::new(options);
let stop_request_tx = player.get_stop_tx();
let start_time = SystemTime::now();
let handles = vec![
spawn(move || {
player.start(&tether_agent);
}),
spawn(move || {
let mut time_to_end = false;
while !time_to_end {
if let Ok(elapsed) = start_time.elapsed() {
if elapsed > std::time::Duration::from_secs(3) {
println!("Time to stop! {}s elapsed", elapsed.as_secs());
stop_request_tx
.send(true)
.expect("failed to send stop request via channel");
time_to_end = true;
}
}
}
println!("Playback should have stopped now; wait 1 more seconds...");
std::thread::sleep(std::time::Duration::from_secs(1));
println!("...Bye");
}),
];
for handle in handles {
handle.join().expect("failed to join handle");
}
}Auto Trait Implementations§
impl RefUnwindSafe for TetherPlaybackUtil
impl Send for TetherPlaybackUtil
impl !Sync for TetherPlaybackUtil
impl Unpin for TetherPlaybackUtil
impl UnwindSafe for TetherPlaybackUtil
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