TokenManager.kt
# coroutines
v
TokenManager.kt
z
I don’t think you need
tokenChannel
to be a channel – you’re never actually receiving from it. It can just be a simple
AtomicReference
.
v
It is not in the sample, but there is coroutine that persists each new token in local storage.
z
Ah
Have you considered how you want consumers of the channel to behave if your
tokenUpdateJob
coroutine throws an exception? You might want to wrap it in a try/catch and close the channel if there’s an error. Although if the channel consumer shares a parent CoroutineScope, structured concurrency should take care of cancelling everything anyway.