July 2018
Intermediate to advanced
266 pages
7h 11m
English
This type of channel has a buffer size bigger than zero and up to Int.MAX_VALUE - 1, and will suspend the senders when the amount of elements it contains reaches the size of the buffer. It can be created by sending any positive value lower than Int.MAX_VALUE to Channel():
val channel = Channel<Int>(50)
It can also be created by calling its constructor directly:
val arrayChannel = ArrayChannel<Int>(50)
This type of channel will suspend the sender when the buffer is full, and resume it when one or more of the items is retrieved, as the following for example:
fun main(args: Array<String>) = runBlocking { val time = measureTimeMillis { val channel = Channel<Int>(4) val sender = launch { repeat(10) { channel.send(it) println("Sent ...
Read now
Unlock full access