https://kotlinlang.org logo
#ballast
Title
# ballast
a

Adrian Witaszak

02/13/2023, 8:19 PM
Creating infinite flow. I get
Copy code
20:15:18.730  W  BallastException(_cause=java.lang.IllegalStateException: This InputHandlerScope has already been closed, handled=true, latestState=State(isUserSignedIn=false), inputSequence=[src.txconnected.mobox.shared_ui.component.root.RootContract$Inputs$ObserveUserState@ce9ec24])
Here is my input:
Copy code
RootContract.Inputs.ObserveUserState -> observeFlows(
            "observeUserState",
            flow {
                while (true) {
                    postInput(RootContract.Inputs.CheckUserState)
                }
            }
        )

        RootContract.Inputs.CheckUserState -> postInput(
            RootContract.Inputs.ChangeUserSignInState(
                SDK.sessionManager.isLoggedIn
            )
        )

        is RootContract.Inputs.ChangeUserSignInState -> updateState { 
            it.copy(isUserSignedIn = input.newState) 
        }
    }
And i start it in the RootContent:
Copy code
internal fun RootContent(
) {
    val coroutineScope = rememberCoroutineScope()
    val snackbarHostState = remember { SnackbarHostState() }
    val vm = remember(coroutineScope) {
        RootViewModel(
            viewModelCoroutineScope = coroutineScope,
            displayErrorMessage = { snackbarHostState.showSnackbar(it) },
        )
    }
    val state by vm.observeStates().collectAsState()
    vm.trySend(RootContract.Inputs.ObserveUserState)
    RouterContent(state.isUserSignedIn)
}
In router gets false will got back to Login page:
Copy code
internal fun RouterContent(isSignedIn: Boolean) {
    val scope = rememberCoroutineScope()
    val router: Router<RouterScreens> = remember(scope) {
            RouterViewModel(scope,)
        }
    val routerState: Backstack<RouterScreens> by router.observeStates().collectAsState()

    if (!isSignedIn) {
        router.trySend(RouterContract.Inputs.ReplaceTopDestination(
            RouterScreens.Login.matcher.routeFormat
        ))
    }
c

Casey Brooks

02/13/2023, 8:26 PM
You’re not actually emitting values to the Flow in
ObserveUserState
because you’re calling
postInput
instead of
emit
. This is breaking the intended DSL scoping. Do this instead:
Copy code
observeFlows(
    "observeUserState",
    flow {
        while (true) {
            emit(RootContract.Inputs.CheckUserState)
        }
    }
)
or else drop the Flow and call
postInput
from within a
sideJob()
Copy code
sideJob("observeUserState") {
    while (true) {
        postInput(RootContract.Inputs.CheckUserState)
    }
}
a

Adrian Witaszak

02/13/2023, 8:28 PM
Alright forgot about emit..
thx have a look 🤪
That generates a lot of logs. I removed the interceptor for now. Is there a way of excluding log for single input without creating custom Logging Interceptor?
c

Casey Brooks

02/13/2023, 9:13 PM
You can provide a custom
BallastLogger
instance, and manually filter the logs from there, or just configure your log viewer to exclude logs containing
CheckUserState
. Logging in Ballast is very basic and relies more on filtering from your chosen Logging library instead of implementing that level of log fidelity in the library.
2 Views