java - 无法执行 Single.create 中的任何内容 - rxjava
问题描述
嗨,我有一个store
具有 Single.create 的函数,目前只有一条 Timber 日志消息。
Single.create 中的代码不会被执行。
public Single<String> store(final String filePath, final byte[] fileContents) {
Timber.d("inside store method");
Single<String> single = Single.create(subscriber -> {
Timber.d("Inside single");
});
return single.subscribeOn(Schedulers.io());
}
}
这个 Store 函数从两个地方调用,一个来自它所在的类,它工作正常,但是当我从 Single.create 内的不同类代码调用它时,它不会被执行。
从 kotlin 类调用不起作用的调用
关于为什么会发生这种情况的任何建议?
您的帮助建议将不胜感激。
谢谢R
编辑
Single.create 这是 rx 包
/**
* Returns a Single that will execute the specified function when a {@link SingleSubscriber} executes it or
* a {@link Subscriber} subscribes to it.
* <p>
* <img width="640" height="200" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.create.png" alt="">
* <p>
* Write the function you pass to {@code create} so that it behaves as a Single: It should invoke the
* SingleSubscriber {@link SingleSubscriber#onSuccess onSuccess} and/or
* {@link SingleSubscriber#onError onError} methods appropriately.
* <p>
* A well-formed Single must invoke either the SingleSubscriber's {@code onSuccess} method exactly once or
* its {@code onError} method exactly once.
* <p>
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code create} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param <T>
* the type of the item that this Single emits
* @param f
* a function that accepts an {@code SingleSubscriber<T>}, and invokes its {@code onSuccess} or
* {@code onError} methods as appropriate
* @return a Single that, when a {@link Subscriber} subscribes to it, will execute the specified function
* @see <a href="http://reactivex.io/documentation/operators/create.html">ReactiveX operators documentation: Create</a>
*/
public static <T> Single<T> create(OnSubscribe<T> f) {
return new Single<T>(f);
}
这就是我从 kotlin 调用的方式
val result = pdfTicketStorage.store(offlinePrintedTicketInfo.pdfTicketFilePath, offlinePrintedTicketInfo.pdfTicketContent)
Timber.d("OfflineDataLib - postPrintedTicket - result - " + result )
解决方案
推荐阅读
- node.js - 单击登录后,页面会重新加载,然后我会返回登录弹出窗口。我正在使用 Nodejs - Auth0 - Heroku
- git - GitLab 克隆错误 RPC 失败;curl 56 请求的 URL 返回错误:401
- angular - 从回调函数访问不同命名空间中的属性和方法
- excel - 如何根据开始和长度动态填充单元格
- aws-amplify - AWS Amplify Storage:在存储中未找到提供商的插件
- javascript - ReactJS - 是什么让 bundle.js 变大
- android - 如何在 android studio 模拟器中修复此错误?
- asp.net - 如何从现有镜像构建 Docker 容器
- java - 如何修复 Apache Beam 中的“加入无界 PCollections 目前仅支持带有触发器的非全局窗口”
- django - 基于类视图的Loggin django没有工作,