use of com.koushikdutta.ion.Loader.LoaderEmitter in project ion by koush.
the class IonRequestBuilder method execute.
<T> ResponseFuture<T> execute(final AsyncParser<T> parser, Runnable cancel) {
assert parser != null;
final Uri uri = prepareURI();
AsyncHttpRequest request = null;
if (uri != null) {
request = prepareRequest(uri);
Type type = parser.getType();
for (Loader loader : ion.loaders) {
ResponseFuture<T> quickLoad = loader.load(ion, request, type);
if (quickLoad != null)
return quickLoad;
}
}
EmitterTransform<T> ret = new EmitterTransform<T>(cancel) {
EmitterTransform<T> self = this;
@Override
protected void transform(LoaderEmitter emitter) throws Exception {
super.transform(emitter);
parser.parse(this.emitter).setCallback(new FutureCallback<T>() {
@Override
public void onCompleted(Exception e, T result) {
postExecute(self, e, result);
}
});
}
};
if (uri == null) {
ret.setComplete(new Exception("Invalid URI"));
return ret;
}
ret.initialRequest = request;
getLoaderEmitter(ret);
return ret;
}
use of com.koushikdutta.ion.Loader.LoaderEmitter in project ion by koush.
the class IonRequestBuilder method execute.
<T> EmitterTransform<T> execute(final DataSink sink, final boolean close, final T result, final Runnable cancel) {
EmitterTransform<T> ret = new EmitterTransform<T>(cancel) {
@Override
protected void cleanup() {
super.cleanup();
if (close)
sink.end();
}
EmitterTransform<T> self = this;
@Override
protected void transform(LoaderEmitter emitter) throws Exception {
super.transform(emitter);
Util.pump(this.emitter, sink, new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
postExecute(self, ex, result);
}
});
}
};
getLoaderEmitter(ret);
return ret;
}
Aggregations