SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
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