<@U86J330VD> I can't delay inside the main thread ...
# coroutines
o
@SUPERCILEX I can't delay inside the main thread because it should wait for 1 minute, which is a long time for the app(its networked)
o
like this here
Copy code
override fun fetchAndSaveFavorites(): Observable<List<WishResponse>> =
        carsService.getFavorites().map { favorites ->
            database.favoritesDao().wipeTable()
            database.favoritesDao().insert(favorites)
            favorites
        }
insert now accepts List<FavoriteCars> not List<WishResponse> anymore, but the data required to make a FavoriteCar is inside each WishResponse
e
Copy code
launch { 
    delay(60000)
    // do something after 1 minute
}
o
but then i could launch a new coroutine in each loop of the while loop
which could result in a cascading effect
e
Copy code
launch {
    while(true) {
        delay(60000)
        // do something _every_ minute
    }
}
s
@elizarov nooooooo
while(true)
is bad. Should be
while(isActive)
so you don't shoot yourself in the foot later cancelling stuff
Or does
delay
actually handle that for you?
e
No bad.
delay
is cancellable. You can do
while(isActive)
but you don’t have to.
s
Damn, that's sweet! TIL 😁