Use callOnQueue() instead of latch

Reviewed By: astreet

Differential Revision: D2717989

fb-gh-sync-id: 9770e773015838301f6e9520a1ca7a283f647de7
This commit is contained in:
Alexander Blom 2015-12-12 14:19:31 -08:00 committed by facebook-github-bot-7
parent 8de172e92d
commit 01e291751a
1 changed files with 7 additions and 13 deletions

View File

@ -16,7 +16,6 @@ import java.io.StringWriter;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -137,13 +136,11 @@ public class CatalystInstanceImpl implements CatalystInstance {
@Override @Override
public void runJSBundle() { public void runJSBundle() {
try { try {
final CountDownLatch initLatch = new CountDownLatch(1); mJSBundleHasLoaded = mCatalystQueueConfiguration.getJSQueueThread().callOnQueue(
mCatalystQueueConfiguration.getJSQueueThread().runOnQueue( new Callable<Boolean>() {
new Runnable() {
@Override @Override
public void run() { public Boolean call() throws Exception {
Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!"); Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!");
mJSBundleHasLoaded = true;
incrementPendingJSCalls(); incrementPendingJSCalls();
@ -159,14 +156,11 @@ public class CatalystInstanceImpl implements CatalystInstance {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
} }
initLatch.countDown(); return true;
} }
}); }).get(LOAD_JS_BUNDLE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
Assertions.assertCondition( } catch (Exception t) {
initLatch.await(LOAD_JS_BUNDLE_TIMEOUT_MS, TimeUnit.MILLISECONDS), throw new RuntimeException(t);
"Timed out loading JS!");
} catch (InterruptedException e) {
throw new RuntimeException(e);
} }
} }