Hello my locationmanager is using a kotlin channel...
# coroutines
s
Hello my locationmanager is using a kotlin channel with this code
Copy code
private val myLocationsChannel = Channel<MyLocation>(Channel.BUFFERED)
val myLocationsFlow = myLocationsChannel.receiveAsFlow()
How can i send an error to the channel? For example when i havent location permissions. Thanks
j
Channels can by default only model "fatal" errors closing the channel (using
channel.close(cause)
). If you want errors that can be recovered and allow you to continue with regular events, you'll need to materialize them (represent them as part of the channel item type). One way to do this neatly is to use a sealed class representing either location events or errors.
s
ok thanks
h
Often the reason, why the location was not updated (eg permissions) itself is useless, so you could send
null
too.
s
yep is another option but i liked the option of use sealed class