daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun main(args: Array<String>) = runBlocking<Unit> {
  2.     val squares = produceSquares(5)
  3.     squares.consumeEach { println(it) }
  4.     println("Done")
  5. }
  6.  
  7. fun CoroutineScope.produceSquares(max: Int): ReceiveChannel<Int> = produce {
  8.     for (x in 1..max) {
  9.         send(x * x)
  10.     }
  11. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top