Skip to content
Permalink
Browse files

Allow passing in a CoroutineScope to goAsync

  • Loading branch information...
ianhanniballake committed Jul 22, 2019
1 parent 70242c9 commit 9587fec907d1b017733557def4ad2aee58b8e5f2
@@ -17,12 +17,16 @@
package com.google.android.apps.muzei.util

import android.content.BroadcastReceiver
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

fun BroadcastReceiver.goAsync(block: suspend () -> Unit) {
fun BroadcastReceiver.goAsync(
coroutineScope: CoroutineScope = GlobalScope,
block: suspend () -> Unit
) {
val result = goAsync()
GlobalScope.launch {
coroutineScope.launch {
block()
result.finish()
}
@@ -175,7 +175,7 @@ class LegacySourceService : Service(), LifecycleOwner {
updateSources(packageName)
}
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
goAsync {
goAsync(lifecycleScope) {
val source = LegacyDatabase.getInstance(context)
.sourceDao().getCurrentSource()
if (source != null && packageName == source.componentName.packageName) {

0 comments on commit 9587fec

Please sign in to comment.
You can’t perform that action at this time.