'Call second coroutine function without blocking the first function
I have coroutine function that return the result of a network call.
I want my function to return the result and call another function in a parallel way without waiting for the second function to finish.
This is my function
suspend fun getResult() : NetworkResponse<ApiResult, ApiError>?
{
return withContext(Dispatchers.IO) {
val localData : LocalData? = _localDataSource?.await()
val result : NetworkResponse<ApiResult, ApiError>? = fetchFromNetwork(_localDataSource, localData).getOrNull()
doAdditionalWork(localData, result)
result
}
}
And this is my second function
private suspend fun doAdditionalWork(localData : LocalData?, apiResponse : NetworkResponse<ApiResult, ApiError>?)
{
delay(5000)
//...
}
I just want the function 1 to return the result without waiting for the function 2. So how can i do it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
