Is there a library to provide extension functions ...
# coroutines
j
Is there a library to provide extension functions for RxJava 1 types? Like
Single.await()
? The official lib only supports RxJava 2 😞
j
No support has been droped
RxJava 1 is discontinued for quite a wile already
But it is easy to implement your own
j
do you mind explaining more about implementing one?
or giving some hints
j
You can use
suspendCoroutine
Here's an example:
Copy code
suspend fun <T> Single<T>.await(): T = supendCancellableCoroutine { cont ->
	val disposable = subscribe(
		{ cont.resume(it) }, // onSuccess
		{ cont.resumeWithException(it) } // onError
	)
	
	cont.invokeOnCancellation {
		disposable.dispose()
	}
}
My example is only on conceptual level, and probably doesn't compile
j
thank you very much! appreciate it 🙂
j
Actually my exmple would work with RxJava 2 (I just tried)
👏 1
So you only have to adapt to the RxJava1 API, which I don't know well.
🙇‍♂️ 1
z
The Rx2 adapter library actually does a lot of work to manage backpressure etc, you might want to consider just using that library with the Rx1/Rx2 adapter library from David Karnok
g
You can copy old (dropped) implementation of Rx1 adapter to you project