Skip to content

Commit

Permalink
Avoid extra lock for subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
iampatbrown committed Nov 3, 2024
1 parent 3879d2c commit 1aed887
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ final class CurrentValueRelay<Output>: Publisher {
}

func send(_ value: Output) {
self.lock.sync {
let subscriptions = self.lock.sync {
self.currentValue = value
return self.subscriptions
}
for subscription in self.lock.sync({ self.subscriptions }) {
for subscription in subscriptions {
subscription.receive(value)
}
}
Expand Down

0 comments on commit 1aed887

Please sign in to comment.