blob: 507d4cf2222e0856a2ca615472ecd447e765e0a1 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Vsevolod Tolstopyatov26b86e92018-06-07 15:24:31 +03005@file:JvmMultifileClass
6@file:JvmName("ChannelsKt")
7
Vsevolod Tolstopyatov96191342018-04-20 18:13:33 +03008package kotlinx.coroutines.experimental.channels
9
10import kotlinx.coroutines.experimental.*
11
12// -------- Operations on SendChannel --------
13
14/**
15 * Adds [element] into to this channel, **blocking** the caller while this channel [Channel.isFull],
16 * or throws exception if the channel [Channel.isClosedForSend] (see [Channel.close] for details).
17 *
18 * This is a way to call [Channel.send] method inside a blocking code using [runBlocking],
19 * so this function should not be used from coroutine.
20 */
21public fun <E> SendChannel<E>.sendBlocking(element: E) {
22 // fast path
23 if (offer(element))
24 return
25 // slow path
26 runBlocking {
27 send(element)
28 }
29}