Commit 6b314dae authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Create a VLCIO coroutines context

As IO operations are blocking, create a dedicated coroutines dispatcher
to not block the CommonPool
parent 46767eb1
......@@ -3,15 +3,16 @@ package org.videolan.vlc.util
import android.os.Looper
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.newSingleThreadContext
val VLCIO = newSingleThreadContext("vlc-io")
fun runBackground(runnable: Runnable) {
if (Looper.myLooper() != Looper.getMainLooper())
runnable.run()
if (Looper.myLooper() != Looper.getMainLooper()) runnable.run()
else launch { runnable.run() }
}
fun runOnMainThread(runnable: Runnable) {
if (Looper.myLooper() == Looper.getMainLooper())
runnable.run()
if (Looper.myLooper() == Looper.getMainLooper()) runnable.run()
else launch(UI) { runnable.run() }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment