jvmMain.channels.Channels.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-coroutines-core Show documentation
Show all versions of kotlinx-coroutines-core Show documentation
Coroutines support libraries for Kotlin
/*
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
@file:JvmMultifileClass
@file:JvmName("ChannelsKt")
package kotlinx.coroutines.channels
import kotlinx.coroutines.*
// -------- Operations on SendChannel --------
/**
* Adds [element] into to this channel, **blocking** the caller while this channel [Channel.isFull],
* or throws exception if the channel [Channel.isClosedForSend] (see [Channel.close] for details).
*
* This is a way to call [Channel.send] method inside a blocking code using [runBlocking],
* so this function should not be used from coroutine.
*/
public fun SendChannel.sendBlocking(element: E) {
// fast path
if (offer(element))
return
// slow path
runBlocking {
send(element)
}
}