Skip to content

Commit

Permalink
reduce nesting in track_new_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Nov 7, 2024
1 parent 2a6b750 commit c26c709
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,28 +1817,30 @@ impl BreezServices {
interval.set_missed_tick_behavior(MissedTickBehavior::Skip);
loop {
tokio::select! {
_ = interval.tick() => {
let tip_res = cloned.chain_service.current_tip().await;
match tip_res {
Ok(next_block) => {
debug!("got tip {:?}", next_block);
if next_block > current_block {
_ = cloned.sync().await;
_ = cloned.on_event(BreezEvent::NewBlock{block: next_block}).await;
}
current_block = next_block
},
Err(e) => {
error!("failed to fetch next block {}", e)
}
};
}
_ = interval.tick() => { }

_ = shutdown_receiver.changed() => {
debug!("New blocks task has completed");
return;
}
}

let next_block = match cloned.chain_service.current_tip().await {
Ok(next_block) => next_block,
Err(e) => {
error!("failed to fetch next block {}", e);
continue;
}
};

debug!("got tip {:?}", next_block);
if next_block > current_block {
_ = cloned.sync().await;
_ = cloned
.on_event(BreezEvent::NewBlock { block: next_block })
.await;
}
current_block = next_block
}
});
}
Expand Down

0 comments on commit c26c709

Please sign in to comment.