Viktor Qvarfordt
05/12/2019, 9:30 PMbdawg.io
05/12/2019, 9:59 PMchannel.take(5).toList()Viktor Qvarfordt
05/12/2019, 10:24 PMchannel.take is marked with ObsoleteCoroutineAPIr4zzz4k
05/12/2019, 10:36 PMsend to it, coroutine suspends till someone `receive`s a value, and in your case there is only one coroutine so noone would be able to consume values.
So to make the code work,
1. Add channel.close() to the end,
2. Add Unit as the last statement (or don't use single-expression for your main with runBlocking)
3. Either create buffered channel (Channel<Int>(10)) or split the sending and receiving parts into concurrent coroutines, for example, by wrapping repeat in launch { ... }.bdawg.io
05/12/2019, 11:49 PMbdawg.io
05/12/2019, 11:56 PMproduce coroutine and closing the channel when finished using it: https://pl.kotl.in/CTmfVmaR8
(since the produce coroutine only repeats 5, it will automatically close the channel, so it's not necessary with that coroutine builder)Dico
05/13/2019, 1:20 AMsendDico
05/13/2019, 1:21 AMr4zzz4k
05/13/2019, 7:06 AMViktor Qvarfordt
05/13/2019, 10:04 AMbdawg.io
05/13/2019, 1:26 PMViktor Qvarfordt
05/13/2019, 6:36 PMbdawg.io
05/13/2019, 6:44 PMsend method suspends your method until something `receive`s it. Since you were doing send and receive in the same coroutine, the send was suspending your coroutine, which means it hung forever because no one else was going to receive.bdawg.io
05/13/2019, 6:46 PMViktor Qvarfordt
05/13/2019, 9:09 PM