sailxjx
11/15/2017, 8:54 AMgildor
11/15/2017, 8:56 AMwhile (true) {
if (queue.size < 10000) {
queue.add(getElement()) // getElement can be suspend function that gets element asynchronously
} else {
delay(QUEUE_DELAY) // Optional delay between retry, but probably don't need it
}
}
sailxjx
11/15/2017, 9:02 AMdelay
in the while loop, and this code block should put into a suspend function. Is this means I can only use sleep
in the place of delay
without coroutine?gildor
11/15/2017, 9:07 AMgetElement
sailxjx
11/15/2017, 9:11 AMdelay
and every getElement
returns null, this will cause an infinite cycle and make the cpu usage to 100%gildor
11/15/2017, 9:13 AMsailxjx
11/15/2017, 9:16 AM