From b0bc9b1888a98c99edc80f35133616c2687a5ae9 Mon Sep 17 00:00:00 2001 From: Nagata Parama Aptana <61454123+lifers@users.noreply.github.com> Date: Fri, 16 Aug 2024 12:29:54 -0400 Subject: [PATCH] Take the guard as late as possible Co-authored-by: Kenny Kerr --- crates/libs/core/src/event.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/libs/core/src/event.rs b/crates/libs/core/src/event.rs index 50eca22d1f..c04b2f8352 100644 --- a/crates/libs/core/src/event.rs +++ b/crates/libs/core/src/event.rs @@ -29,10 +29,10 @@ impl Event { /// Registers a delegate with the event object. pub fn add(&self, delegate: &T) -> Result { - let mut guard = self.delegates.write().unwrap(); let new_delegate = Delegate::new(delegate)?; let token = new_delegate.to_token(); let new_iter = once(new_delegate); + let mut guard = self.delegates.write().unwrap(); let new_list = if let Some(old_delegates) = guard.as_ref() { Arc::from_iter(old_delegates.iter().cloned().chain(new_iter))