https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

Schadenfreude

10/22/2018, 2:27 PM
Hey guys, any coroutine gurus around who can help me out with something?
c

christophsturm

10/22/2018, 2:28 PM
just ask
💯 1
s

Schadenfreude

10/22/2018, 2:30 PM
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

louiscad

10/22/2018, 2:44 PM
@Schadenfreude I think you should make an interface with
suspend
functions, and implement it twice, wrapping both in app billing systems.
s

Schadenfreude

10/22/2018, 2:56 PM
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

louiscad

10/22/2018, 3:08 PM
You should just use
suspendCoroutine { continuation -> … }
g

gildor

10/22/2018, 3:13 PM
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

gildor

10/22/2018, 3:14 PM
If you need just wrap 1 call back and return another implementation just as fallback it will be even simpler
1
u

uli

10/22/2018, 3:33 PM
Can't you just depend on coroutines.rx and await the PublishSubject