https://kotlinlang.org logo
#coroutines
Title
# coroutines
e

elizarov

11/29/2017, 10:55 AM
Copy code
val reqs: List<Request> = ... // list of original requests
val chan = Channel<Request>()
launch { for (req in reqs) chan.send(req) } // send all reqs to chan
repeat(n) { // craete a pool of limited number workers
    launch { for (req in chan) processRequest(req) }
}
g

gildor

11/30/2017, 12:56 AM
I’m curious, can we use
produce
instead of channel + launch in this case:
Copy code
val reqs: List<Request> = ... // list of original 
val chan = produce {
    for (req in reqs) send(req)
}
repeat(n) { // craete a pool of limited number workers
    launch { for (req in chan) processRequest(req) }
}
Any drawbacks?
e

elizarov

11/30/2017, 7:05 AM
Using
produce
for it is a great idea 👍
4 Views