Reading the documentation for the billing client, there is a section entitled Querying with Kotlin extensions. The example shown includes a dispatch to Dispatchers.IO like this:
val productDetailsResult = withContext(Dispatchers.IO) {
billingClient.queryProductDetails(params.build())
}
The withContext is shown on other suspending functions as well. queryProductDetails in the ktx lib and the others are all suspending functions. Why do the docs include withContext? I can't imagine the purpose of making a suspending function that just blocked the thread, it should internally dispatch to Dispatchers.IO in my opinion, rendering the withContext calls in the example code superfluous.
Is my assessment correct, can I omit the withContext blocks without blocking the Main thread (assuming the calling context is on Dispatchers.Main)? I wasn't able to determine what it was doing with the debugger, and there doesn't seem to be any documentation on the extension functions.
What I want to write is just:
val productDetailsResult = billingClient.queryProductDetails(params.build())
The decompiled
Javacode ofqueryProductDetailsextension function looks like the following:We can see that it uses
queryProductDetailsAsyncunder the hood, so it runs asynchronously. Therefore we can conclude that the call is not blocking and we don't need to wrapbillingClient.queryProductDetails(params.build())intowithContext(Dispatchers.IO):