I am calling an Api from a suspend function and after successful execution of it, I need to call another Api (which is also in another suspend function).
suspend fun updateSubscription(body: Map<String, Any>): NetworkResponse<SubscriptionUpdateResponse> =
withContext(Dispatchers.IO) {
val response = networkManager.execute(
networkManager.updateSubscriptionApi(body)
)
val data = response.body()
if (response.isSuccessful) {
fetchSubscriptions() // suspend function which call another api, should run without blocking
}
return@withContext parseNetworkResponse(response, data)
}
I want to call updateSubscriptionApi
and after it successful execution, call fetchSubscription
without blocking and return updateSubscription
result.
For now, fetchSubscription
is also blocking updateSubscription
. I tried to call updateSubscription
in async
block like this without any success.
async{ updateSubscription() }
How can I call fetchSubscriptions()
without blocking updateSubscription
.