Search in sources :

Example 1 with Future

use of com.koushikdutta.async.future.Future in project ion by koush.

the class Ion method getPendingRequestCount.

public int getPendingRequestCount(Object group) {
    synchronized (this) {
        FutureSet members = inFlight.get(group);
        if (members == null)
            return 0;
        int ret = 0;
        for (Future future : members.keySet()) {
            if (!future.isCancelled() && !future.isDone())
                ret++;
        }
        return ret;
    }
}
Also used : Future(com.koushikdutta.async.future.Future)

Example 2 with Future

use of com.koushikdutta.async.future.Future in project AndroidAsync by koush.

the class AsyncHttpClient method execute.

public <T> SimpleFuture<T> execute(AsyncHttpRequest req, final AsyncParser<T> parser, final RequestCallback<T> callback) {
    final FutureAsyncHttpResponse cancel = new FutureAsyncHttpResponse();
    final SimpleFuture<T> ret = new SimpleFuture<T>();
    execute(req, 0, cancel, new HttpConnectCallback() {

        @Override
        public void onConnectCompleted(Exception ex, final AsyncHttpResponse response) {
            if (ex != null) {
                invoke(callback, ret, response, ex, null);
                return;
            }
            invokeConnect(callback, response);
            Future<T> parsed = parser.parse(response).setCallback(new FutureCallback<T>() {

                @Override
                public void onCompleted(Exception e, T result) {
                    invoke(callback, ret, response, e, result);
                }
            });
            // reparent to the new parser future
            ret.setParent(parsed);
        }
    });
    ret.setParent(cancel);
    return ret;
}
Also used : HttpConnectCallback(com.koushikdutta.async.http.callback.HttpConnectCallback) SimpleFuture(com.koushikdutta.async.future.SimpleFuture) Future(com.koushikdutta.async.future.Future) TimeoutException(java.util.concurrent.TimeoutException) AsyncSSLException(com.koushikdutta.async.AsyncSSLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FutureCallback(com.koushikdutta.async.future.FutureCallback) SimpleFuture(com.koushikdutta.async.future.SimpleFuture)

Aggregations

Future (com.koushikdutta.async.future.Future)2 AsyncSSLException (com.koushikdutta.async.AsyncSSLException)1 FutureCallback (com.koushikdutta.async.future.FutureCallback)1 SimpleFuture (com.koushikdutta.async.future.SimpleFuture)1 HttpConnectCallback (com.koushikdutta.async.http.callback.HttpConnectCallback)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1