Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support trySendBlocking() Coroutines API in Kotlin/Native #2983

Closed
artdfel opened this issue Oct 14, 2021 · 0 comments
Closed

Support trySendBlocking() Coroutines API in Kotlin/Native #2983

artdfel opened this issue Oct 14, 2021 · 0 comments
Labels

Comments

@artdfel
Copy link

artdfel commented Oct 14, 2021

NOTE: This is a mirror for the https://youtrack.jetbrains.com/issue/KT-49230, made to follow the kotlinx.coroutines Contributing Guidelines.
All the credits should go to @jeffdgr8(I hope I'm not mentioning the wrong person).

trySendBlocking() is only available in Kotlin/JVM. But the implementation doesn't seem to have any JVM-specific requirements. Copying the extension function to a KMM shared module compiles just fine, only warning about InternalCoroutinesApi usage in ChannelResult:

@Throws(InterruptedException::class)
public fun <E> SendChannel<E>.trySendBlocking(element: E): ChannelResult<Unit> {
    trySend(element).onSuccess { return ChannelResult.success(Unit) }
    return runBlocking {
        val r = runCatching { send(element) }
        if (r.isSuccess) ChannelResult.success(Unit)
        else ChannelResult.closed(r.exceptionOrNull())
    }
}

Can this function be added to support Kotlin/Native?

The deprecated sendBlocking() function that functions similarly is available, but can't be replaced with trySendBlocking() as it suggests.

qwwdfsad added a commit that referenced this issue Dec 6, 2021
woainikk pushed a commit that referenced this issue Dec 14, 2021
Move trySendBlocking from the JVM to the concurrent source-set
to make it available on K/N.

Fixes #2983
yorickhenning pushed a commit to yorickhenning/kotlinx.coroutines that referenced this issue Jan 28, 2022
Move trySendBlocking from the JVM to the concurrent source-set
to make it available on K/N.

Fixes Kotlin#2983
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
Move trySendBlocking from the JVM to the concurrent source-set
to make it available on K/N.

Fixes Kotlin#2983
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants