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

uli

03/09/2017, 4:54 PM
@kevinherron :
Copy code
fun SelectBuilder<Unit>.onPriorityRequest(): Unit {
        priorityRequests.onReceive {
            priorityCount++
            it.execute()
        }
    }

    fun SelectBuilder<Unit>.onRegularRequest(): Unit {
        regularRequests.onReceive {
            priorityCount = 0
            it.execute()
        }
    }

    while (true) {
        if (priorityCount >= priorityRatio) {
            select<Unit> {
                onPriorityRequest()
                onRegularRequest()
            }
        } else {
            select<Unit> {
                onRegularRequest()
                onPriorityRequest()
            }
        }
    }