Skip to content

Commit

Permalink
Only cancel the children of the ShotsRepository.
Browse files Browse the repository at this point in the history
ShotsRepository is a singleton that lives in the scope of the app. Once cancelAllSearches was called, no other calls could have been triggered, because the parent job was canceled (once a job was cancelled it cannot be active again. See https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html ).
So for now, we're just cancelling the children.

Future, ideal fix - remove the job launching from the Repository
  • Loading branch information
florina-muntenescu committed Nov 15, 2018
1 parent 9529074 commit 109ab8b
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.plaidapp.core.dribbble.data.api.model.Shot
import io.plaidapp.core.dribbble.data.search.SearchRemoteDataSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

Expand All @@ -33,7 +34,7 @@ class ShotsRepository constructor(
private val dispatcherProvider: CoroutinesDispatcherProvider
) {

private var parentJob = Job()
private val parentJob = Job()
private val scope = CoroutineScope(dispatcherProvider.main + parentJob)

private val inflight = mutableMapOf<String, Job>()
Expand All @@ -58,7 +59,7 @@ class ShotsRepository constructor(
}

fun cancelAllSearches() {
parentJob.cancel()
parentJob.cancelChildren()
inflight.clear()
}

Expand Down

0 comments on commit 109ab8b

Please sign in to comment.