Skip to content
Snippets Groups Projects
Commit 9778750a authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Browser: cancel task using a coroutineScope

parent 85622346
No related branches found
No related tags found
No related merge requests found
Pipeline #8642 passed with stage
in 26 minutes and 27 seconds
......@@ -53,7 +53,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
val loading = MutableLiveData<Boolean>().apply { value = false }
protected var mediabrowser: MediaBrowser? = null
private var parsingJob : CompletableJob? = null
private var parsingJob : Job? = null
private val foldersContentMap = SimpleArrayMap<MediaLibraryItem, MutableList<MediaLibraryItem>>()
protected lateinit var browserChannel : Channel<Media>
......@@ -171,9 +171,8 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
val directories: MutableList<AbstractMediaWrapper> = ArrayList()
val files: MutableList<AbstractMediaWrapper> = ArrayList()
foldersContentMap.clear()
val job = SupervisorJob(coroutineContext[Job]).also { parsingJob = it }
try {
withContext(Dispatchers.IO+job) {
coroutineScope { // allow child coroutine to be cancelled without closing the actor.
parsingJob = launch (Dispatchers.IO) {
initBrowser()
var currentParsedPosition = -1
loop@ while (++currentParsedPosition < currentMediaList.size) {
......@@ -218,7 +217,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
files.clear()
}
}
} catch (ignored: CancellationException) {}
}
parsingJob = null
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment