Skip to content

Instantly share code, notes, and snippets.

@s3va
Created July 17, 2025 08:14
Show Gist options
  • Select an option

  • Save s3va/6fd37b6f34786a266a8b49fbe8f49d5e to your computer and use it in GitHub Desktop.

Select an option

Save s3va/6fd37b6f34786a266a8b49fbe8f49d5e to your computer and use it in GitHub Desktop.
Coroutine Scope of Service (or something like this).
class YourService : Service() {
private val job = SupervisorJob()
private val scope = CoroutineScope(Dispatchers.IO + job)
fun foo() {
scope.launch {
// Call your suspend function
}
}
override fun onDestroy() {
super.onDestroy()
job.cancel()
}
}
// https://stackoverflow.com/a/63407811/11798617
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment