This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Coroutine-based solution for delayed and periodic work. May fire once (if [interval] omitted) | |
* or periodically ([startDelay] defaults to [interval] in this case), replacing both | |
* `Observable.timer()` & `Observable.interval()` from RxJava. | |
* | |
* In contrast to RxJava, intervals are calculated since previous run completion; this is more | |
* convenient for potentially long work (prevents overlapping) and does not suffer from queueing | |
* multiple invocations in Doze mode on Android. | |
* | |
* Dispatcher is inherited from scope, may be overridden via [context] parameter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rx.Observable | |
import rx.Observer | |
import rx.Subscriber | |
import rx.Subscription | |
import rx.functions.Action0 | |
import rx.functions.Action1 | |
fun <T> Observable<T>.uiSubscribe(schedulers: Schedulers, subscriber: Subscriber<in T>): Subscription { | |
return subscribeOn(schedulers.io) | |
.observeOn(schedulers.mainThread) |