Index: talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java |
diff --git a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java |
index 5e6cc52895c8ce44fb63201f632c3cb269044777..33402f700ba014c6393c1ea708bd1e3a5616bc30 100644 |
--- a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java |
+++ b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java |
@@ -27,6 +27,9 @@ |
package org.webrtc; |
+import android.os.Handler; |
+ |
+import java.util.concurrent.Callable; |
import java.util.concurrent.CountDownLatch; |
final class ThreadUtils { |
@@ -100,4 +103,27 @@ final class ThreadUtils { |
} |
}); |
} |
+ |
+ /** |
+ * Post |callable| to |handler| and wait for the result. |
+ */ |
+ public static <V> V invokeUninterruptibly(final Handler handler, final Callable<V> callable) { |
+ class Result { |
+ public V value; |
+ } |
+ final Result result = new Result(); |
+ final CountDownLatch barrier = new CountDownLatch(1); |
+ handler.post(new Runnable() { |
+ @Override public void run() { |
+ try { |
+ result.value = callable.call(); |
+ } catch (Exception e) { |
+ throw new RuntimeException("Callable threw exception: " + e); |
hbos
2015/10/12 08:20:19
On second thought, this will catch InterruptedExce
magjed_webrtc
2015/10/12 14:29:01
Actually, this is correct. The InterruptedExceptio
|
+ } |
+ barrier.countDown(); |
+ } |
+ }); |
+ awaitUninterruptibly(barrier); |
+ return result.value; |
+ } |
} |