This is the flow I need to follow to create a file record in my server
Black arrow is flow
Red arrow is dependency
This is one big function
I need help designing this in rxjava that make them happen sequentially while the later single is able to get the reference
I can create some single for each time taking task
public static Single<byte[]> processData(byte[] fileData))
public static Single<APIResponse> callAPI(String id, byte[] processedData)
public static Single<UploadResponse> uploadData(String url)
This is my attempt
I tried using flatMap's resultSelector as described here
Retrofit and RxJava: How to combine two requests and get access to both results?
private static Single<FinalResult> bigFunction(String id, int type, String jwt, byte[] fileData){
return processData(fileData).flatMap(new Function<byte[], SingleSource<APIResponse>>() {
@Override
public SingleSource<APIResponse> apply(byte[] processedData) throws Throwable {
return callAPI(id, processedData);
}
}, new BiFunction<byte[], APIResponse, UploadResponse>() {
@Override
public FinalResult apply(byte[] processData, APIResponse apiResponse) throws Throwable {
if (processData.size() > LIMIT){
uploadData(apiResponse.getUrl()); // I am stuck here how to return a FinalResult() after this uploadData() is complete
}else{
return new FinalResult(); // if no need to upload, done
}
}
});
}