Skip to content

Commit

Permalink
LockIsolated.withValue closure should be sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Oct 31, 2023
1 parent 6155400 commit ee5a504
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/ConcurrencyExtras/LockIsolated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class LockIsolated<Value>: @unchecked Sendable {
/// - Parameter operation: An operation to be performed on the the underlying value with a lock.
/// - Returns: The result of the operation.
public func withValue<T: Sendable>(
_ operation: (inout Value) throws -> T
_ operation: @Sendable (inout Value) throws -> T
) rethrows -> T {
try self.lock.sync {
var value = self._value
Expand Down Expand Up @@ -93,15 +93,17 @@ extension LockIsolated where Value: Sendable {
}
}

@available(*, deprecated, message: "Lock isolated values should not be equatable")
extension LockIsolated: Equatable where Value: Equatable {
public static func == (lhs: LockIsolated, rhs: LockIsolated) -> Bool {
lhs.withValue { lhsValue in rhs.withValue { rhsValue in lhsValue == rhsValue } }
lhs.value == rhs.value
}
}

@available(*, deprecated, message: "Lock isolated values should not be hashable")
extension LockIsolated: Hashable where Value: Hashable {
public func hash(into hasher: inout Hasher) {
self.withValue { hasher.combine($0) }
hasher.combine(self.value)
}
}

Expand Down

0 comments on commit ee5a504

Please sign in to comment.