Does this look like a good way to manage a session...
# coroutines
d
Does this look like a good way to manage a session interaction:
Copy code
fun dispatch(event: ChatSessionClientEvent): Flow<ChatSessionServerEvent> {
        return flow {
            when (event) {
                is MakeChoice -> makeChoice(event)
                ReloadSettings -> reloadSettings()
                is RequestChatState -> requestChatState(event)
                ResetSettings -> resetSettings()
                SaveSettings -> saveSettings()
                is SetTools -> setTools(event)
                is ToolCallResults -> toolCallResults(event)
                is UpdateSettings -> updateSettings(event)
                is UserMessage -> userMessage(event)
            }
        }.shareIn(this, SharingStarted.WhileSubscribed())
    }
Where the event handlers will emit ChatSessionServerEvent instances.
e
creating a new flow with a single element each time the function is called seems unlikely to be useful
d
It isn’t a single element, multiple events can be emitted from a single command.
In any case, I reorganized this to use two Channels instead. One for incoming commands, the other for outgoing state updates.