Skip to content

Commit

Permalink
Create event subscription earlier to avoid missed events
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Oct 11, 2023
1 parent 1eaebac commit f2b7149
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/src/network/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ impl<'a> Monitor<'a> {
}

async fn run(self) -> Result<()> {
self.handle_all_branches_changed().await?;

// Important: make sure to create the event subscription first, before calling
// `handle_all_branches_changed` otherwise we might miss some events.
let mut events = pin!(Throttle::new(
events(self.vault.event_tx.subscribe()),
Duration::from_secs(1)
));

self.handle_all_branches_changed().await?;

while let Some(event) = events.next().await {
match event {
BranchChanged::One(branch_id) => self.handle_branch_changed(branch_id).await?,
Expand Down

0 comments on commit f2b7149

Please sign in to comment.