Wai-Wai Ng
06/07/2023, 2:27 PMval job: Job? = null
fun refresh() {
if (!job?.isCompleted) return
job = launch {
withTimeoutOrNull(10_000) {
// actual code here
}
}
}
Is this sensible or is there a better way of doing this?franztesca
06/07/2023, 2:41 PMclass MyClass(private val scope: CoroutineScope) {
private val refreshJob = scope.launch(start = CoroutineStart.LAZY) {
// Refresh logic
}
// True if actually starting it, false if already started
fun refresh(): Boolean = refreshJob.start()
}