mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 11:07:24 +01:00
Offers an interface to BaseEoseManager objects
This commit is contained in:
@@ -29,17 +29,25 @@ import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
interface IEoseManager {
|
||||
fun invalidateFilters(ignoreIfDoing: Boolean = false)
|
||||
|
||||
fun destroy()
|
||||
|
||||
fun printStats()
|
||||
}
|
||||
|
||||
abstract class BaseEoseManager<T>(
|
||||
val client: INostrClient,
|
||||
val allKeys: () -> Set<T>,
|
||||
) {
|
||||
) : IEoseManager {
|
||||
protected val logTag: String = this.javaClass.simpleName
|
||||
|
||||
private val orchestrator = SubscriptionController(client)
|
||||
|
||||
abstract fun updateSubscriptions(keys: Set<T>)
|
||||
|
||||
fun printStats() = orchestrator.printStats(logTag)
|
||||
override fun printStats() = orchestrator.printStats(logTag)
|
||||
|
||||
fun newSubscriptionId() = if (isDebug) logTag + newSubId() else newSubId()
|
||||
|
||||
@@ -52,19 +60,16 @@ abstract class BaseEoseManager<T>(
|
||||
// Refreshes observers in batches.
|
||||
private val bundler = BundledUpdate(500, Dispatchers.Default)
|
||||
|
||||
fun invalidateFilters() {
|
||||
bundler.invalidate {
|
||||
forceInvalidate()
|
||||
}
|
||||
override fun invalidateFilters(ignoreIfDoing: Boolean) {
|
||||
bundler.invalidate(ignoreIfDoing, ::forceInvalidate)
|
||||
}
|
||||
|
||||
fun forceInvalidate() {
|
||||
updateSubscriptions(allKeys())
|
||||
|
||||
orchestrator.updateRelays()
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
override fun destroy() {
|
||||
bundler.cancel()
|
||||
orchestrator.destroy()
|
||||
if (isDebug) {
|
||||
|
||||
Reference in New Issue
Block a user