Skip to content

Instantly share code, notes, and snippets.

@mreram
Last active July 25, 2020 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mreram/ba88af0a9d58673ea45ce1deef78794b to your computer and use it in GitHub Desktop.
Save mreram/ba88af0a9d58673ea45ce1deef78794b to your computer and use it in GitHub Desktop.
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