Guest User

Untitled

a guest
Jan 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. fun main(args: Array<String>) = runBlocking<Unit> {
  2. val numbers = produceNumbers(5)
  3. val doubledNumbers = produceDouble(numbers)
  4. doubledNumbers.consumeEach { println(it) }
  5. println("Done")
  6. }
  7.  
  8. fun CoroutineScope.produceNumbers(max: Int): ReceiveChannel<Int> = produce {
  9. for (x in 1..max) {
  10. send(x)
  11. }
  12. }
  13.  
  14. fun CoroutineScope.produceDouble(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = produce {
  15. numbers.consumeEach { send(it * 2) }
  16. }
Add Comment
Please, Sign In to add comment