Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.consume
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Test
class BroadcastChannelTest {
@ExperimentalCoroutinesApi
companion object {
val broadcastChannel = BroadcastChannel<String>(2)
val openSubscription = broadcastChannel.openSubscription()
}
@ExperimentalCoroutinesApi
@Test
fun `send and receive a bullshit`() {
runBlockingTest {
launch {
openSubscription.consume {
println(receive())
}
}
launch {
delay(20000)
broadcastChannel.send("heyyyyy" + 1)
}
}
}
}
@mreram
Copy link
Author

mreram commented Jul 25, 2020

will print:
heyyyyy1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment