Abdul Moeed
10/13/2022, 7:17 AMoverride suspend fun getBusStopModel(): Flow<Resource<SmartBusStop>> {
return flow {
while(currentCoroutineContext().isActive){
try{
val data = api.getBusService(STOPID).toSmartBusStop()
emit(Resource.Success<SmartBusStop>(data))
} catch (e: HttpException){
emit(Resource.Error(e.localizedMessage ?: "An unexpected error occurred"))
} catch (e: IOException){
emit(Resource.Error("Couldn't reach server. Check your internet connection"))
} catch (e: Exception){
emit(Resource.Error(e.stackTraceToString()))
}
delay(10000)
}
}
}
This is called and collected in the view model.
I want to ask, is there any better way to achieve a periodic API call. I have looked into work manager a little bitRobert Williams
10/13/2022, 9:06 AMRobert Williams
10/13/2022, 9:10 AMRobert Williams
10/13/2022, 9:10 AMAbdul Moeed
10/13/2022, 11:24 AMRobert Williams
10/13/2022, 11:30 AMAbdul Moeed
10/13/2022, 11:33 AMLukáš Kúšik
10/13/2022, 2:07 PMfixedPeriodTicker
or fixedDelayTicker
functionsMartin Nowosad
10/13/2022, 8:43 PMMartin Nowosad
10/13/2022, 8:44 PMMartin Nowosad
10/13/2022, 8:44 PMDaniel Bejan
10/14/2022, 5:55 AM