Skip to content
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

Replace java.time with kotlin.time in websockets configuration #4315

Merged
merged 3 commits into from
Sep 23, 2024

Conversation

osipxd
Copy link
Member

@osipxd osipxd commented Sep 13, 2024

Subsystem
Client/Server, ktor-server-websockets, ktor-client-core, ktor-shared:ktor-websockets

Motivation
KTOR-7446 Replace java.time options in Websockets plugin

Solution
Replaced java.time.Duration with kotlin.time.Duration. Moved Duration extensions to the common source set. Added Duration support to a websocket client.

@osipxd osipxd self-assigned this Sep 13, 2024
* Ping interval or `null` to disable pinger. Please note that pongs will be handled despite this setting.
*/
@Deprecated("Use variant with kotlin.time.Duration", level = DeprecationLevel.ERROR)
public inline var DefaultWebSocketServerSession.pingInterval: Duration?
Copy link
Member Author

Choose a reason for hiding this comment

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

Now I'm not sure that it worth to keep these extensions with deprecation as they could confuse users 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think it would be a little confusing. It would be nice to drop the JVM source path entirely for this plugin too. It's an easy migration for them anyway.

* Ping interval meaning pinger is disabled.
* @see pingIntervalMillis
*/
public const val PINGER_DISABLED: Long = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

To be discussed: With this constant code seems a bit clearer, but I'm not sure if I chose the right place for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be best under the WebSockets companion since that's the only type users are generally exposed to.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only thing I don't like is that it will be two constants, one for a client plugin and another for a server plugin.
I thought about making these constants pointing to the same constant in the shared module, but it will result in imports ambiguity.

public const val PINGER_DISABLED: Long = DefaultWebSocketSession.PINGER_DISABLED

Copy link
Member Author

Choose a reason for hiding this comment

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

@bjhham, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, maybe in that case it can be a top-level declaration.

* Ping interval or `null` to disable pinger. Please note that pongs will be handled despite this setting.
*/
@Deprecated("Use variant with kotlin.time.Duration", level = DeprecationLevel.ERROR)
public inline var DefaultWebSocketServerSession.pingInterval: Duration?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think it would be a little confusing. It would be nice to drop the JVM source path entirely for this plugin too. It's an easy migration for them anyway.

* Ping interval meaning pinger is disabled.
* @see pingIntervalMillis
*/
public const val PINGER_DISABLED: Long = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be best under the WebSockets companion since that's the only type users are generally exposed to.

@osipxd osipxd force-pushed the osipxd/websocket-kotlin-time branch 3 times, most recently from e7426af to 7217fc8 Compare September 23, 2024 13:08
Introduce PINGER_DISABLED constant
@osipxd osipxd merged commit 4fa4a55 into main Sep 23, 2024
11 of 16 checks passed
@osipxd osipxd deleted the osipxd/websocket-kotlin-time branch September 23, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants