fixes in build
This commit is contained in:
core/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/core/ktor/client/content
ktor
client
src
commonMain
kotlin
com
insanusmokrassar
postssystem
ktor
client
tests
src
test
kotlin
com
insanusmokrassar
postssystem
ktor
tests
12
ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/ktor/client/FlowsWebsockets.kt
12
ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/ktor/client/FlowsWebsockets.kt
@ -11,8 +11,7 @@ import kotlinx.coroutines.flow.*
|
||||
* @param checkReconnection This lambda will be called when it is required to reconnect to websocket to establish
|
||||
* connection. Must return true in case if must be reconnected. By default always reconnecting
|
||||
*/
|
||||
inline fun <reified T> createStandardWebsocketFlow(
|
||||
client: HttpClient,
|
||||
inline fun <reified T> HttpClient.createStandardWebsocketFlow(
|
||||
url: String,
|
||||
crossinline checkReconnection: (Throwable?) -> Boolean = { true },
|
||||
crossinline conversation: suspend (ByteArray) -> T
|
||||
@ -20,7 +19,7 @@ inline fun <reified T> createStandardWebsocketFlow(
|
||||
val correctedUrl = url.asCorrectWebSocketUrl
|
||||
|
||||
return channelFlow {
|
||||
val producerScope = this
|
||||
val producerScope = this@channelFlow
|
||||
do {
|
||||
val reconnect = try {
|
||||
safely(
|
||||
@ -28,7 +27,7 @@ inline fun <reified T> createStandardWebsocketFlow(
|
||||
throw it
|
||||
}
|
||||
) {
|
||||
client.ws(
|
||||
ws(
|
||||
correctedUrl
|
||||
) {
|
||||
while (true) {
|
||||
@ -62,8 +61,3 @@ inline fun <reified T> createStandardWebsocketFlow(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T> HttpClient.createStandardWebsocketFlow(
|
||||
url: String,
|
||||
crossinline conversation: suspend (ByteArray) -> T
|
||||
) = createStandardWebsocketFlow(this, url, conversation)
|
||||
|
@ -40,8 +40,7 @@ class WebsocketsTest {
|
||||
val client = HttpClient {
|
||||
install(io.ktor.client.features.websocket.WebSockets)
|
||||
}
|
||||
val incomingWebsocketFlow = createStandardWebsocketFlow(
|
||||
client,
|
||||
val incomingWebsocketFlow = client.createStandardWebsocketFlow(
|
||||
"$serverUrl/$suburl",
|
||||
{ false } // always skip reconnection
|
||||
) {
|
||||
|
Reference in New Issue
Block a user