我正在尝试使用RxJava 2以异步方式对S3执行MultiPart upload。
compile "io.reactivex.rxjava2:rxjava:2.2.2"
我有Flowable
个零件。对于每个部分,我在TransferManager
对象上调用一个方法,该方法立即返回一个Upload
对象。
Upload::isDone
方法javadoc如下:
/**
* Returns whether or not the transfer is finished (i.e. completed successfully,
* failed, or was canceled).
*
* @return Returns <code>true</code> if this transfer is finished (i.e. completed successfully,
* failed, or was canceled). Returns <code>false</code> if otherwise.
*/
public boolean isDone();
这就是我想要做的:
TransferManager
:
public class TransferManager {
public Upload transfer(Part part) {
return new Upload();
}
}
Part
:
public class Part {}
Upload
:
import java.util.Random;
public class Upload {
public boolean isDone() {
return new Random().nextInt(10) == 1;
}
}
这就是我在做什么:
TransferManager tm = new TransferManager();
Flowable.just(new Part(), new Part(), new Part(), new Part(), new Part())
.map(part -> tm.transfer(part))
.subscribe(upload -> {
do {
} while(!upload.isDone());
});
RxJava正确的方法是什么?
答案 0 :(得分:0)
如果我理解您说的没错,您想知道何时upload.isDone()
,然后在订阅中执行一些操作
.map(part -> tm.transfer(part))
.filter(upload -> upload.isDone())
.subscribe(upload -> {...});
我认为,这可以帮助