Hey there, I am using Kotlin coroutines to perform API calls asynchronously. Said API expects a non-decreasing nonce with every request. This seems to requires some control over the execution order of the coroutines since frequently a request with a larger nonce will invalidate older requests with a smaller nonce.
For example:
suspend fun submit() {
val one = GlobalScope.async { api.doThis() }
val two = GlobalScope.async { api.doThat() }
val three = GlobalScope.async { api.doStuff() }
...
}
In this example, the first request has a nonce of 1, the second a nonce of 2, the third a nonce of… 3. If now the third request is executed first, it effectively invalidates the other two requests since their nonces are now too small.
That said, it feels somewhat stupid to impose these requirements while using asynchronous requests. But maybe there is a way to achieve this without going fully sequential. Thanks!