You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
It is a problem that client reconnection is not addressed
Describe the solution you'd like
This is just a workaround, but here we go. It primarly uses flows and might be a
solution to be integrated with the library.
@Mr3zee if you see this not fit as an issue I am very sorry. but I thought it might help someone
Some utilities:
fun <T> Flow<T>.firstShareStateInBlocking(scope:CoroutineScope): StateFlow<T> {
val started:SharingStarted=SharingStarted.Eagerlyreturn shareIn(scope, started, replay =1).let {
it.stateIn(scope, started, runBlocking { it.first() })
}
}
// this is helpful if using composefun <T:R, R> Flow<T>.collectAsStateIn(
coroutineScope:CoroutineScope,
initial:R,
): State<R> {
val state = mutableStateOf(initial)
onEach { state.value = it }.launchIn(coroutineScope)
return state
}
Creating a client state that reacts to session changes and reconnection requests
And to use the client (in compose, but can be used elsewhere):
val remoteServiceState = rpcClientState
.map { it.withService<MyRemoteService>() }
.firstShareStateInBlocking(viewModelScope) // <-- or other scope
@OptIn(ExperimentalCoroutinesApi::class)
val someFlowValue by remoteServiceState
.flatMapLatest { it.someServiceFlow }
.onEach { newFlowValue ->/**/ } // optional - to peek the value when changed
.collectAsStateIn(viewModelScope, initial =null) // <-- or other scope
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
It is a problem that client reconnection is not addressed
Describe the solution you'd like
This is just a workaround, but here we go. It primarly uses flows and might be a
solution to be integrated with the library.
Some utilities:
Creating a client state that reacts to session changes and reconnection requests
And to use the client (in compose, but can be used elsewhere):
The text was updated successfully, but these errors were encountered: