Is there any support for priority by coroutines?
# coroutines
s
Is there any support for priority by coroutines?
e
What are you trying to achive?
s
Its a list view in an app. Each item has an associated async task and scrolling the list creates a task to fetch new items. I'm trying to give that fetch task more priority over the other pending tasks
btw all tasks perform IO over network
e
I fear that is not something coroutines can help you with. I assume that fetch task goes somewhere over the network, so you should look to your network IO stack to see if it supports tweaking priorities of outstanding requests.
Coroutines themselves would take no cpu time — they just fire off a network request. So prioritizing coroutines themselves is of no help.
It is network requests you need to prioritize
s
I was hoping if Dispatchers supported some concept of priority
e
You can write a prioritized dispatcher. But that would not help in solving your problem.
Dispatchers manage CPU consumption. They don’t manage network consumption. And in your problem the limited resource you want to prioritize is a network, not cpu.
s
Okay
r
I may be totally wrong as I still didn't use
select
once, but my idea is as follows: one channel for posting `Unit`s or objects with some data when fetching is needed, one channel for posting items to run actions upon and one coroutine selecting from those channels and running corresponding IO operations for both of these.
select
is biased to the upper statements. So your coroutine would usually select from second channel and run actions on items, but as soon as there is a message in first channel, it would be taken instead of second one and fetching gets a prioritized processing.