Home > Enterprise >  Kotlin channel - is there a non-suspending receive?
Kotlin channel - is there a non-suspending receive?

Time:03-07

Apparently if we call channel.receive() against an empty channel, it suspends, which is exactly as documented here in official docs. Is there a way to immediately return a null instead, like what ConcurrentLinkedQueue's poll() does?

CodePudding user response:

Yes, we can use tryReceive():

channel.tryReceive().getOrNull()
  • Related