WebWorkers: Add MessageQueueThreadRegistry

Summary:
public

It is helpful to be able to access the current MessageQueueThread like you would the current Looper. I would do this exactly as Looper does it, but we have forked implementations of MQT for the native bridge and MQT is an interface that can't hold private members.

Reviewed By: lexs

Differential Revision: D2779072

fb-gh-sync-id: 0ff841d8c490b971697c8e5d45f9c0a57668376b
This commit is contained in:
Andy Street
2016-01-04 12:00:18 -08:00
committed by facebook-github-bot-0
parent 8c9c7e6286
commit 42e5b2a5bc
3 changed files with 82 additions and 16 deletions

View File

@@ -91,6 +91,18 @@ public class SimpleSettableFuture<T> implements Future<T> {
return mResult;
}
/**
* Convenience wrapper for {@link #get(long, TimeUnit)} that re-throws get()'s Exceptions as
* RuntimeExceptions.
*/
public @Nullable T getOrThrow(long timeout, TimeUnit unit) {
try {
return get(timeout, unit);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
}
private void checkNotSet() {
if (mReadyLatch.getCount() == 0) {
throw new RuntimeException("Result has already been set!");