Skip to content

Conversation

MahdiBM
Copy link
Contributor

@MahdiBM MahdiBM commented Oct 4, 2022

Motivation:

Lock has recently been deprecated in favor of NIOLock.
The warnings claim that this is supposed to be a mere rename, but the API of NIOLock misses withLockVoid(_:) compared to Lock, which is unexpected to some users.

Modifications:

NIOLock now has the withLockVoid(_:) too.

Result:

Lock and NIOLock will have a more similar API and users can move to NIOLock easier.
This will also resolve #2275.

@swift-server-bot
Copy link

Can one of the admins verify this patch?

10 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Oct 4, 2022
@Lukasa
Copy link
Contributor

Lukasa commented Oct 4, 2022

@swift-server-bot test this please

@Lukasa Lukasa enabled auto-merge (squash) October 4, 2022 09:42
@Lukasa Lukasa merged commit e9eeaad into apple:main Oct 4, 2022
@@ -140,6 +140,12 @@ extension NIOLock {
}
return try body()
}

// specialise Void return (for performance)
Copy link
Member

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(_:).

Copy link
Contributor Author

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 😅

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #2281

Copy link
Contributor Author

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)

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NIOLock missing withLockVoid(_:)
5 participants