这是我在服务器中创建文件记录需要遵循的流程
我需要帮助在 rxjava 中设计它,使它们按顺序发生,而后面的单曲能够获得参考
我可以为每次执行任务创建一些单曲
public static Single<byte[]> processData(byte[] fileData))
public static Single<APIResponse> callAPI(String id, byte[] processedData)
public static Single<UploadResponse> uploadData(String url)
这是我尝试
使用 flatMap 的 resultSelector 的尝试,如此处所述
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
}
}
});
}