fixes in build
This commit is contained in:
parent
3d3d184636
commit
c3cf3f161a
@ -16,15 +16,13 @@ class WriteContentRepoKtorClient(
|
||||
private val baseUrl: String,
|
||||
private val client: HttpClient = HttpClient()
|
||||
) : WriteContentRepo {
|
||||
override val contentCreatedFlow: Flow<RegisteredContent> = createStandardWebsocketFlow(
|
||||
client,
|
||||
override val contentCreatedFlow: Flow<RegisteredContent> = client.createStandardWebsocketFlow(
|
||||
"$baseUrl/$contentCreatedFlowRoute"
|
||||
) {
|
||||
standardKtorSerialFormat.load(RegisteredContent.serializer(), it)
|
||||
}
|
||||
|
||||
override val contentDeletedFlow: Flow<RegisteredContent> = createStandardWebsocketFlow(
|
||||
client,
|
||||
override val contentDeletedFlow: Flow<RegisteredContent> = client.createStandardWebsocketFlow(
|
||||
"$baseUrl/$contentDeletedFlowRoute"
|
||||
) {
|
||||
standardKtorSerialFormat.load(RegisteredContent.serializer(), it)
|
||||
|
@ -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
|
||||
) {
|
||||
|
Loading…
Reference in New Issue
Block a user