kirillrakhman
07/22/2016, 3:28 PMfun Subscription.autoUnsubscribe(naviComponent: NaviComponent) = apply { naviComponent.addListener(Event.DESTROY) { unsubscribe() } }
fun NaviComponent.asyncRx(coroutine c: RxController.() -> Continuation<Unit>) {
RxController(this).c().resume(Unit)
}
class RxController internal constructor(
private val naviComponent: NaviComponent
) {
suspend fun <V> Observable<V>.awaitFirst(x: Continuation<V>) {
this.first().subscribeWithContinuation(x)
}
private fun <V> Observable<V>.subscribeWithContinuation(x: Continuation<V>) {
subscribe(x::resume, x::resumeWithException).autoUnsubscribe(naviComponent)
}
}