From 138b22348c796f8cca31c76538f6cbbb37580b8b Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 18 Feb 2023 19:08:52 -0500 Subject: [PATCH] Makes sure Websocket dispatchers are using IO threads --- .../com/vitorpamplona/amethyst/service/relays/Client.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Client.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Client.kt index 6a08b6a9b..5e9548f35 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Client.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Client.kt @@ -1,6 +1,7 @@ package com.vitorpamplona.amethyst.service.relays import java.util.UUID +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import nostr.postr.events.Event @@ -79,7 +80,7 @@ object Client: RelayPool.Listener { override fun onEvent(event: Event, subscriptionId: String, relay: Relay) { // Releases the Web thread for the new payload. // May need to add a processing queue if processing new events become too costly. - GlobalScope.launch { + GlobalScope.launch(Dispatchers.IO) { listeners.forEach { it.onEvent(event, subscriptionId, relay) } } } @@ -87,7 +88,7 @@ object Client: RelayPool.Listener { override fun onError(error: Error, subscriptionId: String, relay: Relay) { // Releases the Web thread for the new payload. // May need to add a processing queue if processing new events become too costly. - GlobalScope.launch { + GlobalScope.launch(Dispatchers.IO) { listeners.forEach { it.onError(error, subscriptionId, relay) } } } @@ -95,7 +96,7 @@ object Client: RelayPool.Listener { override fun onRelayStateChange(type: Relay.Type, relay: Relay, channel: String?) { // Releases the Web thread for the new payload. // May need to add a processing queue if processing new events become too costly. - GlobalScope.launch { + GlobalScope.launch(Dispatchers.IO) { listeners.forEach { it.onRelayStateChange(type, relay, channel) } } } @@ -103,7 +104,7 @@ object Client: RelayPool.Listener { override fun onSendResponse(eventId: String, success: Boolean, message: String, relay: Relay) { // Releases the Web thread for the new payload. // May need to add a processing queue if processing new events become too costly. - GlobalScope.launch { + GlobalScope.launch(Dispatchers.IO) { listeners.forEach { it.onSendResponse(eventId, success, message, relay) } } }