sanchi pinchi
05/06/2026, 1:47 PMsuspend.
Currently, I solved this by extracting the shared logic into an inline function and passing the different read/write operations as lambdas:
Shared logic:
https://github.com/andannn/KWebSocket/blob/main/kwebsocket/common/src/commonMain/kotlin/me/andannn/kwebsocket/KWebSocket.kt#L326
Async usage:
https://github.com/andannn/KWebSocket/blob/main/kwebsocket/async/src/commonMain/kotlin/me/andannn/kwebsocket/AsyncKWebSocket.kt#L119
Blocking usage:
https://github.com/andannn/KWebSocket/blob/main/kwebsocket/blocking/src/commonMain/kotlin/me/andannn/kwebsocket/BlockingKWebSocket.kt#L121
It works, but I’m not sure if this is the right approach. Is there a better Kotlin pattern for sharing protocol code between suspend and non-suspend implementations?