[Android] Create a VLCIO coroutines context

Geoffrey Métais git at videolan.org
Wed Apr 25 14:18:37 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr 25 13:17:25 2018 +0200| [6b314daef3fe93fea1ec0c85973836326b408304] | committer: Geoffrey Métais

Create a VLCIO coroutines context

As IO operations are blocking, create a dedicated coroutines dispatcher
to not block the CommonPool

> https://code.videolan.org/videolan/vlc-android/commit/6b314daef3fe93fea1ec0c85973836326b408304
---

 vlc-android/src/org/videolan/vlc/util/Workers.kt | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/Workers.kt b/vlc-android/src/org/videolan/vlc/util/Workers.kt
index 774861e71..709e8744a 100644
--- a/vlc-android/src/org/videolan/vlc/util/Workers.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Workers.kt
@@ -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() }
 }



More information about the Android mailing list