Guest User

Untitled

a guest
Jan 23rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment