https://kotlinlang.org logo
#coroutines
Title
# coroutines
n

Nikky

08/20/2020, 3:04 PM
is there any library or core functionality for launching a job in a specific interval? or would a "simple"
while(true) { launch { doJob() }: delay(..) }
be the preferred solution ?
g

gildor

08/20/2020, 3:10 PM
Yep, standard while(true) (or while(isActive) is way to go I would be careful with launching coroutines in while(true), you may start too many (before previous is finished), of course it may be fine for your case
n

Nikky

08/20/2020, 3:15 PM
the usecase is a cronjob like thing where i just regularly check if a reminder in a database is due to be delivered and send it to chat.. i guess i should not even launch it
g

gildor

08/20/2020, 3:53 PM
yep, calling a suspend function looks as better solution for such case
4 Views