-
Notifications
You must be signed in to change notification settings - Fork 698
Add withLockVoid(_:)
to NIOLock
#2276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Can one of the admins verify this patch? |
10 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
@swift-server-bot test this please |
@@ -140,6 +140,12 @@ extension NIOLock { | |||
} | |||
return try body() | |||
} | |||
|
|||
// specialise Void return (for performance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this more performant? This just calls down to self.withLock(_:)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't know, i just copy pasted the exact function that Lock
had, including the comment above it 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lukasa should we remove this doc comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a regular comment, not a doc comment. You can remove it if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #2281
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking, is the comment still true about Lock
? (perhaps because Lock
is a class
, unlike NIOLock
?)
// specialise Void return (for performance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment likely stopped being true when the method was marked @inlinable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we just suggest to use withLock
? withLockVoid
is pointless since about Swift 4.2 or so when @inlinable
became available publicly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The honest answer is that I don’t think it’s worth the churn. While withLockVoid
isn’t meaningfully better, plenty of existing code uses it and it makes the deprecation more painful than it needs to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also it doesn’t totally seamlessly get replaced by withLock
, due to single statement return value inference. That can cause you to need to explicitly discard the result, which this avoids.)
Motivation:
Lock
has recently been deprecated in favor ofNIOLock
.The warnings claim that this is supposed to be a mere rename, but the API of
NIOLock
misseswithLockVoid(_:)
compared toLock
, which is unexpected to some users.Modifications:
NIOLock
now has thewithLockVoid(_:)
too.Result:
Lock
andNIOLock
will have a more similar API and users can move toNIOLock
easier.This will also resolve #2275.