fixes in build
This commit is contained in:
parent
3d3d184636
commit
c3cf3f161a
@ -16,15 +16,13 @@ class WriteContentRepoKtorClient(
|
|||||||
private val baseUrl: String,
|
private val baseUrl: String,
|
||||||
private val client: HttpClient = HttpClient()
|
private val client: HttpClient = HttpClient()
|
||||||
) : WriteContentRepo {
|
) : WriteContentRepo {
|
||||||
override val contentCreatedFlow: Flow<RegisteredContent> = createStandardWebsocketFlow(
|
override val contentCreatedFlow: Flow<RegisteredContent> = client.createStandardWebsocketFlow(
|
||||||
client,
|
|
||||||
"$baseUrl/$contentCreatedFlowRoute"
|
"$baseUrl/$contentCreatedFlowRoute"
|
||||||
) {
|
) {
|
||||||
standardKtorSerialFormat.load(RegisteredContent.serializer(), it)
|
standardKtorSerialFormat.load(RegisteredContent.serializer(), it)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val contentDeletedFlow: Flow<RegisteredContent> = createStandardWebsocketFlow(
|
override val contentDeletedFlow: Flow<RegisteredContent> = client.createStandardWebsocketFlow(
|
||||||
client,
|
|
||||||
"$baseUrl/$contentDeletedFlowRoute"
|
"$baseUrl/$contentDeletedFlowRoute"
|
||||||
) {
|
) {
|
||||||
standardKtorSerialFormat.load(RegisteredContent.serializer(), it)
|
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
|
* @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
|
* connection. Must return true in case if must be reconnected. By default always reconnecting
|
||||||
*/
|
*/
|
||||||
inline fun <reified T> createStandardWebsocketFlow(
|
inline fun <reified T> HttpClient.createStandardWebsocketFlow(
|
||||||
client: HttpClient,
|
|
||||||
url: String,
|
url: String,
|
||||||
crossinline checkReconnection: (Throwable?) -> Boolean = { true },
|
crossinline checkReconnection: (Throwable?) -> Boolean = { true },
|
||||||
crossinline conversation: suspend (ByteArray) -> T
|
crossinline conversation: suspend (ByteArray) -> T
|
||||||
@ -20,7 +19,7 @@ inline fun <reified T> createStandardWebsocketFlow(
|
|||||||
val correctedUrl = url.asCorrectWebSocketUrl
|
val correctedUrl = url.asCorrectWebSocketUrl
|
||||||
|
|
||||||
return channelFlow {
|
return channelFlow {
|
||||||
val producerScope = this
|
val producerScope = this@channelFlow
|
||||||
do {
|
do {
|
||||||
val reconnect = try {
|
val reconnect = try {
|
||||||
safely(
|
safely(
|
||||||
@ -28,7 +27,7 @@ inline fun <reified T> createStandardWebsocketFlow(
|
|||||||
throw it
|
throw it
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
client.ws(
|
ws(
|
||||||
correctedUrl
|
correctedUrl
|
||||||
) {
|
) {
|
||||||
while (true) {
|
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 {
|
val client = HttpClient {
|
||||||
install(io.ktor.client.features.websocket.WebSockets)
|
install(io.ktor.client.features.websocket.WebSockets)
|
||||||
}
|
}
|
||||||
val incomingWebsocketFlow = createStandardWebsocketFlow(
|
val incomingWebsocketFlow = client.createStandardWebsocketFlow(
|
||||||
client,
|
|
||||||
"$serverUrl/$suburl",
|
"$serverUrl/$suburl",
|
||||||
{ false } // always skip reconnection
|
{ false } // always skip reconnection
|
||||||
) {
|
) {
|
||||||
|
Loading…
Reference in New Issue
Block a user