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

rockerhieu

07/06/2017, 7:30 AM
moved from #getting-started Any best practice to implement job queue in Kotlin using coroutines? Here is my code
Copy code
val queue = LinkedBlockingQueue<Note>()
    var closed = false

    init {
        async(CommonPool) {
            while (!closed) {
                while (!closed && queue.isEmpty()) {
                    delay(50)
                }
                while (!closed && !queue.isEmpty()) {
                    play(queue.take())
                }
            }
        }
    }
I don't like
delay(50)
and I think it's not sufficient.
Someone mentioned channels and actors. Let me have a look
e

elizarov

07/06/2017, 7:34 AM
3 Views