Buffered actors

An actor can be buffered, the same as any other send channel. By default, all actors are unbuffered: they suspend the caller on send() until the message has been received. To create a buffered actor you need to pass the capacity parameter to the builder:

fun main(args: Array<String>) {
val bufferedPrinter = actor<String>(capacity = 10) {
for (msg in channel) {
println(msg)
}
}

bufferedPrinter.send("hello")
bufferedPrinter.send("world")

bufferedPrinter.close()
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.0.145