Abhimanyu
04/11/2024, 6:40 PMsuspend fun getData1(): DataModel1 { ... }
suspend fun getData1(): DataModel1 { ... }
suspend fun getData1(): DataModel1 { ... }
fun processData(
data1 : DataModel1,
data2 : DataModel2,
data3 : DataModel3,
): Boolean { ... }
I have a suspend method which uses all the above methods like this currently.
suspend fun usageMethod() {
coroutineScope {
val deferred = awaitAll(
async {
getData1()
},
async {
getData1()
},
async {
getData1()
},
)
processData(deferred[0], deferred[1], deferred[2])
}
}
This works as expected, but I am unable to return the Boolean
result of the processData()
from the usageMethod()
.
Note: I am using async to execute all the data fetching methods in parallel.Chrimaeon
04/11/2024, 7:01 PMsuspend fun usageMethod(): Boolean {
return coroutineScope {
val deferred = awaitAll(
async {
getData1()
},
async {
getData2()
},
async {
getData3()
},
)
processData(deferred[0], deferred[1], deferred[2])
}
}
?Abhimanyu
04/11/2024, 7:12 PM