Skip to content

Commit

Permalink
Take the guard as late as possible
Browse files Browse the repository at this point in the history
Co-authored-by: Kenny Kerr <[email protected]>
  • Loading branch information
lifers and kennykerr authored Aug 16, 2024
1 parent bf72954 commit b0bc9b1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/libs/core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl<T: Interface> Event<T> {

/// Registers a delegate with the event object.
pub fn add(&self, delegate: &T) -> Result<i64> {
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))
Expand Down

0 comments on commit b0bc9b1

Please sign in to comment.