From 43c32f0b0ee5f1c1cde41ce396cdb3e8207c6515 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 21 Aug 2023 13:51:03 -0400 Subject: [PATCH] Moves last scope to a class-bound variable. --- .../vitorpamplona/amethyst/service/NostrDataSource.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt index 0c4e6fb31..54e4cac10 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt @@ -10,12 +10,15 @@ import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.utils.TimeUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel import kotlinx.coroutines.launch import java.util.UUID import kotlin.Error abstract class NostrDataSource(val debugName: String) { + private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) + private var subscriptions = mapOf() data class Counter(var counter: Int) @@ -76,6 +79,7 @@ abstract class NostrDataSource(val debugName: String) { fun destroy() { stop() Client.unsubscribe(clientListener) + scope.cancel() bundler.cancel() } @@ -117,8 +121,7 @@ abstract class NostrDataSource(val debugName: String) { } fun resetFilters() { - val scope = CoroutineScope(Job() + Dispatchers.IO) - scope.launch { + scope.launch(Dispatchers.IO) { resetFiltersSuspend() } }