diff --git a/crates/snowbound/src/library.rs b/crates/snowbound/src/library.rs index 4c244307bcfda90d836cb91347026ed40c924531..c982db6c66f56685ceeefc807953928d26d6f408 100644 --- a/crates/snowbound/src/library.rs +++ b/crates/snowbound/src/library.rs @@ -796,14 +796,15 @@ impl Library { ) -> Result> { // The background may hold the replica for a step, which takes a network round trip, // or be making it as an offline copy. - self.open_by(path, notify, Instant::now() + TIMEOUT * 3) + self.open_by(path, Box::new(notify), Instant::now() + TIMEOUT * 3) } - /// `open`, waiting until `deadline` for whatever holds the section's replica. + /// `open`, waiting until `deadline` for whatever holds the section's replica. `notify` is + /// boxed to compile this once rather than once per caller's closure. fn open_by( &self, path: &str, - notify: impl Fn() + Send + 'static, + notify: Box, deadline: Instant, ) -> Result> { let notify = Arc::new(Mutex::new(notify)); @@ -901,7 +902,7 @@ impl Library { path: &str, notify: impl Fn() + Send + 'static, ) -> Result, Box> { - let section = self.open_by(path, notify, Instant::now())?; + let section = self.open_by(path, Box::new(notify), Instant::now())?; let replica = Arc::clone(section.replica()); self.keep(path, section); Ok(replica)