如何计算observable的执行时间
我正在寻找解决方案来衡量一些任务的执行情况
- 我想在某个地方开始计时
- 我想执行一些任务
- 在代码的不同部分,我希望能够停止计时器,我得到执行最终执行时间的结果
我猜这可能是真的使用EventBus来发布开始计数和停止事件。
所以我可以有一个功能:
doSomething(){ //start counting }
在ohter函数中我想访问计数器并调用stop:
otherFunctionWhichCanBeInvokedLater(){ //stop counter and get the duration time }
有没有很好的方法来实现这个在Rx? 我想为此使用Kotlin和RxJava2。
如何使用doOnXXX
挂钩,如下所示:
fun startTimer() { //start counting } fun stopTimer() { //stop counter and get the duration time } fun observe() { Observable.just(...) .doOnSubscribe { startTimer() } .doFinally { stopTimer() } .subscribeBy(...) }
根据您的要求,您可以使用doOnComplete
和/或doOnError
进行设置,以doOnComplete
doOnError
。
- 在Kotlin中使用JPA双向引用的StackOverflowError
- 使用Kotlin在子类中执行静态方法编译?
- 当我退出应用程序时,为什么在Android应用程序中使用Kotlin / rxJava编写android.os.TransactionTooLargeException? (的OnExit /的onPause)?
- Kotlin函数参数:Val不能被重新分配
- url在三星设备中没有加载
- Android Studio 3.0 gradle 3.0.0-beta2,打破Kotlinunit testing覆盖?
- 任何之间的联盟类型? 和Unit
- Kotlin。 基本的JavaFX应用程序
- Kotlin,铸造功能接收器