Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java

Issue 1398283002: Android: Add helper function to synchronously execute Callables on Handler (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698