Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jul 26, 2023
1 parent e185079 commit 56746a6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions iroh/examples/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,19 @@ async fn run(args: Args) -> anyhow::Result<()> {
println!("> ready to accept commands");
println!("> type `help` for a list of commands");

let mut current_watch = Arc::new(std::sync::Mutex::new(None));
let mut current_watch: Arc<std::sync::Mutex<Option<String>>> =
Arc::new(std::sync::Mutex::new(None));
let watch = current_watch.clone();
doc.on_insert(Box::new(move |origin, entry| {
let matcher = watch.lock().unwrap();
if let Some(matcher) = &*matcher {
let key = entry.entry().id().key();
if key.starts_with(matcher.as_bytes()) {
println!("change: {}", fmt_entry(&entry));
}
}
}));

loop {
// wait for a command from the input repl thread
let Some((cmd, to_repl_tx)) = cmd_rx.recv().await else {
Expand Down Expand Up @@ -268,16 +280,6 @@ async fn handle_command(
Cmd::Watch { key } => {
println!("watching key: '{key}'");
current_watch.lock().unwrap().replace(key);
let watch = current_watch.clone();
doc.on_insert(Box::new(move |origin, entry| {
let matcher = watch.lock().unwrap();
if let Some(matcher) = &*matcher {
let key = entry.entry().id().key();
if key.starts_with(matcher.as_bytes()) {
println!("change: {}", fmt_entry(&entry));
}
}
}));
}
Cmd::WatchCancel => match current_watch.lock().unwrap().take() {
Some(key) => {
Expand Down

0 comments on commit 56746a6

Please sign in to comment.