
package com.reactlibrary;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import org.tensorflow.contrib.android.TensorFlowInferenceInterface;

public class RNTensorflowModule extends ReactContextBaseJavaModule {

  private final ReactApplicationContext reactContext;
  private TensorFlowInferenceInterface inference;

  public RNTensorflowModule(ReactApplicationContext reactContext) {
    super(reactContext);
    this.reactContext = reactContext;
  }

  @Override
  public String getName() {
    return "RNTensorflow";
  }

  @ReactMethod
  public void instantiateTensorflow(String modelFilePath) {
    this.inference = new TensorFlowInferenceInterface(reactContext.getAssets(), modelFilePath);
  }

  @ReactMethod
  public void feed(String inputName, double[] src, long[] dims) {
    this.inference.feed(inputName, src, dims);
  }

  @ReactMethod
  public void feed(String inputName, double[] src) {
    this.inference.feed(inputName, src);
  }

  @ReactMethod
  public void run(String[] outputNames) {
    this.inference.run(outputNames);
  }

  @ReactMethod
  public void run(String[] outputNames, boolean enableStats) {
    this.inference.run(outputNames, enableStats);
  }

  @ReactMethod
  public void fetch(String outputName, int outputSize, Callback errorCallback, Callback successCallback) {
    try {
      double[] dst = new double[outputSize];
      this.inference.fetch(outputName, dst);
      successCallback.invoke(dst);
    } catch (Exception e) {
      errorCallback.invoke(e);
    }
  }

  @ReactMethod
  public void graph(Callback errorCallback, Callback successCallback) {
    try {
      successCallback.invoke(this.inference.graph());
    } catch (Exception e) {
      errorCallback.invoke(e);
    }
  }

  @ReactMethod
  public void graphOperation(String operationName, Callback errorCallback, Callback successCallback) {
    try {
      successCallback.invoke(this.inference.graphOperation(operationName));
    } catch (Exception e) {
      errorCallback.invoke(e);
    }
  }

  @ReactMethod
  public void stats(Callback errorCallback, Callback successCallback) {
    try {
      successCallback.invoke(this.inference.getStatString());
    } catch (Exception e) {
      errorCallback.invoke(e);
    }
  }

  @ReactMethod
  public void close() {
    this.inference.close();
  }
}

@@ -58,181 +58,9 @@
 dge.
-Callback;%0Aimport com.facebook.react.bridge.ReactApplicationContext;%0Aimport com.facebook.react.bridge.ReactContextBaseJavaModule;%0Aimport com.facebook.react.bridge.ReactMethod
+*
 ;%0Aim
@@ -1238,56 +1238,23 @@
 ze, 
-Callback errorCallback, Callback successCallback
+Promise promise
 ) %7B%0A
@@ -1359,37 +1359,30 @@
 ;%0A      
-successCallback.invok
+promise.resolv
 e(dst);%0A
@@ -1415,36 +1415,30 @@
 %7B%0A      
-errorCallback.invoke
+promise.reject
 (e);%0A   
@@ -1484,97 +1484,57 @@
 aph(
-Callback errorCallback, Callback successCallback) %7B%0A    try %7B%0A      successCallback.invok
+Promise promise) %7B%0A    try %7B%0A      promise.resolv
 e(th
@@ -1590,36 +1590,30 @@
 %7B%0A      
-errorCallback.invoke
+promise.reject
 (e);%0A   
@@ -1690,97 +1690,57 @@
 me, 
-Callback errorCallback, Callback successCallback) %7B%0A    try %7B%0A      successCallback.invok
+Promise promise) %7B%0A    try %7B%0A      promise.resolv
 e(th
@@ -1818,36 +1818,30 @@
 %7B%0A      
-errorCallback.invoke
+promise.reject
 (e);%0A   
@@ -1887,97 +1887,57 @@
 ats(
-Callback errorCallback, Callback successCallback) %7B%0A    try %7B%0A      successCallback.invok
+Promise promise) %7B%0A    try %7B%0A      promise.resolv
 e(th
@@ -2005,28 +2005,22 @@
     
-errorCallback.invoke
+promise.reject
 (e);

Use promises instead of callbacks