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
Joffrey
12/02/2021, 10:48 AM
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
Sergio Crespo Toubes
12/02/2021, 10:49 AM
ok thanks
h
hfhbd
12/02/2021, 11:23 AM
Often the reason, why the location was not updated (eg permissions) itself is useless, so you could send
null
too.
s
Sergio Crespo Toubes
12/02/2021, 11:24 AM
yep is another option but i liked the option of use sealed class