Java Code Examples for com.facebook.react.common.futures.SimpleSettableFuture

The following are top voted examples for showing how to use com.facebook.react.common.futures.SimpleSettableFuture. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: rnrecord   File: AwaitablePromise.java   View source code 6 votes vote down vote up
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]);
        }
    });
}
 
Example 2
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 3
Project: RNLearn_Project1   File: DevSupportManagerImpl.java   View source code 6 votes vote down vote up
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));
    }
  };
}
 
Example 4
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
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();
  }
}
 
Example 5
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 6
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 7
Project: RNLearn_Project1   File: DevSupportManagerImpl.java   View source code 6 votes vote down vote up
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));
    }
  };
}
 
Example 8
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
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();
  }
}
 
Example 9
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 10
Project: ReactNativeSignatureExample   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 11
Project: ReactNativeSignatureExample   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
/**
 * @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;
}
 
Example 12
Project: ReactNativeSignatureExample   File: DevSupportManagerImpl.java   View source code 6 votes vote down vote up
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));
    }
  };
}
 
Example 13
Project: ReactNativeSignatureExample   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
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();
  }
}
 
Example 14
Project: ReactNativeSignatureExample   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 15
Project: react-native-ibeacon-android   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 16
Project: react-native-ibeacon-android   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
/**
 * @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;
}
 
Example 17
Project: react-native-ibeacon-android   File: DevSupportManagerImpl.java   View source code 6 votes vote down vote up
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));
    }
  };
}
 
Example 18
Project: react-native-ibeacon-android   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
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();
  }
}
 
Example 19
Project: react-native-ibeacon-android   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 20
Project: react-native-box-loaders   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 21
Project: react-native-box-loaders   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
/**
 * @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;
}
 
Example 22
Project: react-native-box-loaders   File: DevSupportManagerImpl.java   View source code 6 votes vote down vote up
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));
    }
  };
}
 
Example 23
Project: react-native-box-loaders   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
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();
  }
}
 
Example 24
Project: react-native-box-loaders   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 25
Project: Ironman   File: MessageQueueThreadImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 26
Project: Ironman   File: DevSupportManagerImpl.java   View source code 6 votes vote down vote up
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));
    }
  };
}
 
Example 27
Project: Ironman   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
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();
  }
}
 
Example 28
Project: Ironman   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 29
Project: ReactNativeSignatureExample   File: CatalystInstanceImpl.java   View source code 5 votes vote down vote up
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();
}
 
Example 30
Project: react-native-ibeacon-android   File: CatalystInstanceImpl.java   View source code 5 votes vote down vote up
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();
}
 
Example 31
Project: react-native-box-loaders   File: CatalystInstanceImpl.java   View source code 5 votes vote down vote up
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();
}