receive(), called on a channel, will suspend until there is an object available, then returns that object.

There is a similar receiveOrNull() function that also suspends until an object is available, then returns that object. The difference is what happens if the channel is closed while receive() or receiveOrNull() is suspended:

  • receive() throws a ClosedReceiveChannelException

  • receiveOrNull() returns null (which might be confusing if null is a valid object to appear in the channel)

You can learn more about this in:
Run Edit