-
Fairly simple repository setup, fetches a table and returns a value as a flow: @Suppress("UNCHECKED_CAST")
override fun <T : SettingsCollection> getSettingsAsFlow(settingType: KClass<T>): Flow<T?> {
return transactions.getAllSettings().asFlow().map {
val settingsTable = it.executeAsOneOrNull()
when (settingType) {
InterfaceSettings::class -> settingsTable?.interface_settings
PlayerSettings::class -> settingsTable?.player_settings
else -> throw Exception("Attempted access of inaccessible or missing setting.")
}
} as Flow<T?> val interfaceSettings by appComponent.settingsRepo
.getSettingsAsFlow(InterfaceSettings::class)
.collectAsStateWithLifecycle(initialValue = null) However I'm getting a lot of warnings about leaked database connections and failing to close the connection. Are these warnings something I need to worry about? I'd assumed returning a table's contents as a Flow would require the connection to stay open?
|
Beta Was this translation helpful? Give feedback.
Answered by
har-nick
Apr 12, 2023
Replies: 1 comment 1 reply
-
Seems to be fixed by passing a Dispatcher using val interfaceSettingsFlow = appComponent.settingsRepo
.getSettingsAsFlow(InterfaceSettings::class)
.flowOn(Dispatchers.IO)
.collectAsStateWithLifecycle(initialValue = null) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
har-nick
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems to be fixed by passing a Dispatcher using
flowOn
.