Search in sources :

Example 1 with GraphRequestBatch

use of com.facebook.GraphRequestBatch in project react-native-fbsdk by facebook.

the class FBGraphRequestModule method start.

/**
     * Send the batch of requests.
     * @param requestBatch
     * @param timeout
     * @param batchCallback
     */
@ReactMethod
public void start(ReadableArray requestBatch, int timeout, Callback batchCallback) {
    GraphRequestBatch batch = new GraphRequestBatch();
    int potentialID = 0;
    int batchID = 0;
    synchronized (this) {
        do {
            batchID = potentialID++;
        } while (mResponses.get(batchID) != null);
        mResponses.put(batchID, Arguments.createMap());
    }
    for (int i = 0; i < requestBatch.size(); i++) {
        GraphRequest request = buildRequest(requestBatch.getMap(i));
        request.setCallback(new GraphRequestCallback(i, batchID));
        batch.add(request);
    }
    batch.setTimeout(timeout);
    GraphRequestBatchCallback callback = new GraphRequestBatchCallback(batchID, batchCallback);
    batch.addCallback(callback);
    batch.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) GraphRequestBatch(com.facebook.GraphRequestBatch) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

GraphRequest (com.facebook.GraphRequest)1 GraphRequestBatch (com.facebook.GraphRequestBatch)1 ReactMethod (com.facebook.react.bridge.ReactMethod)1