blob: d6ebddf2e570f698ef1c36c4653b704c7afa4a2d [file] [log] [blame]
Vsevolod Tolstopyatov26b86e92018-06-07 15:24:31 +03001@file:JvmMultifileClass
2@file:JvmName("ChannelsKt")
3
Vsevolod Tolstopyatov96191342018-04-20 18:13:33 +03004package kotlinx.coroutines.experimental.channels
5
6import kotlinx.coroutines.experimental.*
7
8// -------- Operations on SendChannel --------
9
10/**
11 * Adds [element] into to this channel, **blocking** the caller while this channel [Channel.isFull],
12 * or throws exception if the channel [Channel.isClosedForSend] (see [Channel.close] for details).
13 *
14 * This is a way to call [Channel.send] method inside a blocking code using [runBlocking],
15 * so this function should not be used from coroutine.
16 */
17public fun <E> SendChannel<E>.sendBlocking(element: E) {
18 // fast path
19 if (offer(element))
20 return
21 // slow path
22 runBlocking {
23 send(element)
24 }
25}