Hey guys, any coroutine gurus around who can help ...
# coroutines
s
Hey guys, any coroutine gurus around who can help me out with something?
c
just ask
💯 1
s
Im trying to make a facade that will return either a playstore billing manager or an alipay one. For that I need to wait for a callback which checks if the playstore is available and gives me the result (currently an RxJava2 PublishSubject)
I was wondering whether I can .await() that result and then return the billing manager implementation I want. And more specifically how to do it properly…
l
@Schadenfreude I think you should make an interface with
suspend
functions, and implement it twice, wrapping both in app billing systems.
s
My biggest trouble is waiting for the result of
billingManager.observableIsServiceAvailable
if I can suspend the code until I get that result - the rest is easy…er I think
l
You should just use
suspendCoroutine { continuation -> … }
g
Depends on how original call backs are implemented. If just call backs with success/error you can use suspendCoroutine builder to integrate it with coroutines, same way as any other coroutine adapter for coroutines, just with difference that you actually subscribe on two callbacks and emit only first result
l
g
If you need just wrap 1 call back and return another implementation just as fallback it will be even simpler
1
u
Can't you just depend on coroutines.rx and await the PublishSubject