public AwaitablePromise() { this.resolveFuture = new SimpleSettableFuture<>(); this.rejectFuture = new SimpleSettableFuture(); promise = new PromiseImpl(new Callback() { @Override public void invoke(Object... args) { resolveFuture.set((T)args[0]); } }, new Callback() { @Override public void invoke(Object... args) { rejectFuture.set(args[0]); } }); }
@DoNotStrip @Override public <T> Future<T> callOnQueue(final Callable<T> callable) { final SimpleSettableFuture<T> future = new SimpleSettableFuture<>(); runOnQueue( new Runnable() { @Override public void run() { try { future.set(callable.call()); } catch (Exception e) { future.setException(e); } } }); return future; }
private WebsocketJavaScriptExecutor.JSExecutorConnectCallback getExecutorConnectCallback( final SimpleSettableFuture<Boolean> future) { return new WebsocketJavaScriptExecutor.JSExecutorConnectCallback() { @Override public void onSuccess() { future.set(true); mDevLoadingViewController.hide(); mDevLoadingViewVisible = false; } @Override public void onFailure(final Throwable cause) { mDevLoadingViewController.hide(); mDevLoadingViewVisible = false; FLog.e(ReactConstants.TAG, "Unable to connect to remote debugger", cause); future.setException( new IOException( mApplicationContext.getString(R.string.catalyst_remotedbg_error), cause)); } }; }
public void shutDownContext() { if (mInstance != null) { final ReactContext contextToDestroy = mReactContext; mReactContext = null; mInstance = null; final SimpleSettableFuture<Void> semaphore = new SimpleSettableFuture<>(); UiThreadUtil.runOnUiThread(new Runnable() { @Override public void run() { if (contextToDestroy != null) { contextToDestroy.destroy(); } semaphore.set(null); } }); semaphore.getOrThrow(); } }
/** * Timing module needs to be created on the main thread so that it gets the correct Choreographer. */ protected Timing createTimingModule() { final SimpleSettableFuture<Timing> simpleSettableFuture = new SimpleSettableFuture<Timing>(); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { Timing timing = new Timing(getContext(), mock(DevSupportManager.class)); simpleSettableFuture.set(timing); } }); try { return simpleSettableFuture.get(5000, TimeUnit.MILLISECONDS); } catch (Exception e) { throw new RuntimeException(e); } }
/** * @return a MessageQueueThreadImpl corresponding to Android's main UI thread. */ private static MessageQueueThreadImpl createForMainThread( String name, QueueThreadExceptionHandler exceptionHandler) { Looper mainLooper = Looper.getMainLooper(); final MessageQueueThreadImpl mqt = new MessageQueueThreadImpl(name, mainLooper, exceptionHandler); // Ensure that the MQT is registered by the time this method returns if (UiThreadUtil.isOnUiThread()) { MessageQueueThreadRegistry.register(mqt); } else { final SimpleSettableFuture<Void> registrationFuture = new SimpleSettableFuture<>(); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { MessageQueueThreadRegistry.register(mqt); registrationFuture.set(null); } }); registrationFuture.getOrThrow(); } return mqt; }
private WebsocketJavaScriptExecutor.JSExecutorConnectCallback getExecutorConnectCallback( final ProgressDialog progressDialog, final SimpleSettableFuture<Boolean> future) { return new WebsocketJavaScriptExecutor.JSExecutorConnectCallback() { @Override public void onSuccess() { future.set(true); progressDialog.dismiss(); } @Override public void onFailure(final Throwable cause) { progressDialog.dismiss(); FLog.e(ReactConstants.TAG, "Unable to connect to remote debugger", cause); future.setException( new IOException( mApplicationContext.getString(R.string.catalyst_remotedbg_error), cause)); } }; }
/** * Timing module needs to be created on the main thread so that it gets the correct Choreographer. */ protected Timing createTimingModule() { final SimpleSettableFuture<Timing> simpleSettableFuture = new SimpleSettableFuture<Timing>(); UiThreadUtil.runOnUiThread( new Runnable() { @Override public void run() { Timing timing = new Timing(getContext()); simpleSettableFuture.set(timing); } }); try { return simpleSettableFuture.get(5000, TimeUnit.MILLISECONDS); } catch (Exception e) { throw new RuntimeException(e); } }
private WebsocketJavaScriptExecutor.JSExecutorConnectCallback getExecutorConnectCallback( final AlertDialog progressDialog, final SimpleSettableFuture<Boolean> future) { return new WebsocketJavaScriptExecutor.JSExecutorConnectCallback() { @Override public void onSuccess() { future.set(true); progressDialog.dismiss(); } @Override public void onFailure(final Throwable cause) { progressDialog.dismiss(); FLog.e(ReactConstants.TAG, "Unable to connect to remote debugger", cause); future.setException( new IOException( mApplicationContext.getString(R.string.catalyst_remotedbg_error), cause)); } }; }
private void synchronouslyDisposeBridgeOnJSThread() { final SimpleSettableFuture<Void> bridgeDisposeFuture = new SimpleSettableFuture<>(); mReactQueueConfiguration.getJSQueueThread().runOnQueue( new Runnable() { @Override public void run() { mBridge.destroy(); mBridge.dispose(); bridgeDisposeFuture.set(null); } }); bridgeDisposeFuture.getOrThrow(); }