我的目标是结束completable1
和completable2[0]
。在doOnComplete()
之后我使用mContent
来创建问题。我尝试了上面的代码,但它没有用。
Completable completable1;
final Completable[] completable2 = new Completable[1];
completable1 = AppManagers.getContentManager()
.completeCopy(mContent)
.toCompletable()
.doOnComplete(() -> {
File file = new
File(ImageUtils.getThumbNailPathsForLocalContent(mContent.getId(), 0));
if (!file.exists()) {
final ContentVideoCache videoCache =
AppManagers.getAppContext().getVideoCache();
Uri dataURI = videoCache.getDataURI(mContent);
completable2[0] = AppManagers.getContentManager()
.createThumbnails(mContent.getId(), dataURI)
.toCompletable();
}
});
completable = completable1.concatWith(completable2[0]);
更新:如果completeCopy(mContent)
返回mContent
Completable completable = AppManagers.getContentManager()
.copyIntoShell((Content) selectedContent, mContent)
.flatMapCompletable(new Function<Content, CompletableSource>() {
@io.reactivex.annotations.NonNull
@Override
public CompletableSource apply(@io.reactivex.annotations.NonNull Content content) throws Exception {
return generateThumbnailsForNewContent(content);
}
});
如果我subscribe
到completable
,那么它将在return generateThumbnailsForNewContent(content);
完成后完成吗?
private Completable generateThumbnailsForNewContent(Content mContent) {
File file = new File(ImageUtils.getThumbNailPathsForLocalContent(mContent.getId(), 0));
if (!file.exists()) {
final ContentVideoCache videoCache = AppManagers.getAppContext().getVideoCache();
Uri dataURI = videoCache.getDataURI(mContent);
return AppManagers.getContentManager().createThumbnails(mContent.getId(), dataURI).toCompletable();
}
return Completable.error(new FileNotFoundException());
}
答案 0 :(得分:2)
不确定您在此处尝试完成的操作,但andThen
和defer
是拥有dependent-deferred continuations的运营商:
AppManagers.getContentManager()
.completeCopy(mContent)
.toCompletable()
.andThen(Completable.defer(() -> {
File file = new File(ImageUtils.getThumbNailPathsForLocalContent(
mContent.getId(), 0));
if (!file.exists()) {
final ContentVideoCache videoCache =
AppManagers.getAppContext().getVideoCache();
Uri dataURI = videoCache.getDataURI(mContent);
return AppManagers.getContentManager()
.createThumbnails(mContent.getId(), dataURI)
.toCompletable();
}
return Completable.error(new FileNotFoundException());
}));