gpt4 book ai didi

android - 在 doOnComplete Android 之后继续 Completable

转载 作者:行者123 更新时间:2023-11-29 02:30:10 24 4
gpt4 key购买 nike

我是 RX Java 的新手,我有一个问题。我有一个 completable 并且想在获得一个值并在 emmition 的一个步骤中执行一些操作后继续我的操作。

 if (mIsCopy) {
completable = AppManagers.getContentManager().completeCopy(mContent).toCompletable().andThen(completable).doOnComplete(() -> {
createThumbnailsForNewContent(mContent); //I want this to be happen before completable.cache();
});
}

completable = completable.cache();

completable.subscribe(new SimpleCompletableSubscriber() {
@Override
public void onComplete() {
TypeUtil.empty(mNewTags);
mOriginalSubmitToUsers.clear();
mOriginalSubmitToUsers.addAll(mSubmitToUsers);
mOriginalSubmitToGroups.clear();
mOriginalSubmitToGroups.addAll(mSubmitToGroups);
mOriginalSubmitToChannels.clear();
mOriginalSubmitToChannels.addAll(mSubmitToChannels);
mOriginalSubmitToRelationships.clear();
mOriginalSubmitToRelationships.addAll(mSubmitToRelationships);
mIsCopy = false;
}

createThumbnailsForNewContent(mContent); 返回completable,thx advance.

   public Single<Long> completeCopy(final Content copiedContent) {
return Single.fromCallable(new Callable<Long>() {
@Override
public Long call() throws Exception {
if (!copiedContent.isLocalCopy() || copiedContent.getId() != null) {
throw new IllegalArgumentException("Content passed must be an unsaved local copy.");
}

if (getDBManager().insertOrUpdateContent(copiedContent)) {
if (copiedContent.getCopiedFromCloudID() != null && copiedContent.getCopiedFromCloudID() > 0) {
AppManagers.getAppContext()
.getRequestQueue()
.forRequest(new InitiateCopyRequest(AppUserData.shared.getAccessKey(),
copiedContent.getCopiedFromCloudID()))
.withPriority(RequestQueue.Priority.UPDATE)
.attachLocalID(copiedContent.getId())
.enqueue();
}
} else {
throw new ErrorCodeException(ErrorCodes.UPDATE_CONTENT_FAILED);
}

return copiedContent.getId();

}
}).subscribeOn(getIOScheduler());
}

最佳答案

没有真正理解问题,但根据您的代码,方法 createThumbnailsForNewContent 似乎从未执行过。这是因为 doOnComplete 接受一个 Action 作为参数(这是一个 Runnable 但允许抛出已检查的异常)。

如果你想在前面的 Completable 完成后执行 createThumbnailsForNewContent,你必须使用运算符 andThen(CompletableSource next)

关于android - 在 doOnComplete Android 之后继续 Completable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49921388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com