Sorry if this is not the right place to ask. I'm i...
# coroutines
s
Sorry if this is not the right place to ask. I'm implementing the WebSocket protocol in Kotlin and have both async and blocking APIs. The protocol logic is almost identical; the only difference is whether the API needs
suspend
. 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?