swift-nio
swift-nio copied to clipboard
NIOLock and NIOLockedValueBox are too strict
NIOLock is particularly scary, but NIOLockedValueBox has some limitations too that need to be tidied up.
The following functions are dangerous:
https://github.com/apple/swift-nio/blob/9ff5fddb3d4da3b62dadb8ff83944acf6b0eabf9/Sources/NIOConcurrencyHelpers/NIOLock.swift#L232-L254
Here, withLock
needs to take its closure sending
and the return value needs to be sending
too. In Swift 5, these both need to be Sendable
, with an unchecked version available.
https://github.com/apple/swift-nio/blob/9ff5fddb3d4da3b62dadb8ff83944acf6b0eabf9/Sources/NIOConcurrencyHelpers/NIOLockedValueBox.swift#L35-L39
Here, withLockedValue
needs again to take its closure sending
. Optionally, we could relax its Sendable
requirement, and also return the value sending
, but given our need to remain compatible with Swift 5 we should probably leave it stricter for now. In Swift 5, the closure probably needs to be @Sendable
.