aaverin
09/05/2018, 3:12 PMSeri
09/05/2018, 3:17 PMPaul Woitaschek
09/05/2018, 3:24 PMPublishSubject
?louiscad
09/05/2018, 4:08 PMSuccessOrFailure
through a channel. Otherwise, a sealed class or similar would be greatuli
09/05/2018, 6:26 PMaaverin
09/06/2018, 11:00 AMproduce
– I am wrapping a 3rd party library callback.
So I have a channel, and callback, that will be invoked some time in the future, and might have error inside. If it happens, I need to inform my channel subscriber that something went wrongonError()
?Paul Woitaschek
09/06/2018, 11:07 AMaaverin
09/06/2018, 11:07 AMPaul Woitaschek
09/06/2018, 11:08 AMaaverin
09/06/2018, 11:09 AMsealed class PurchaseEvent {
object Success : PurchaseEvent()
data class Error(val reason: String) : PurchaseEvent()
}
@Singleton
internal class ChanneledPurchaseHandler @Inject constructor() {
val purchaseHandler = object : PurchaseHandler {
override fun onPurchaseSuccess() {
launch { channel.send(PurchaseEvent.Success) }
}
override fun onPurchaseFailure(errorCode: Int, errorMessage: String?) {
launch { channel.send(PurchaseEvent.Error("$errorCode $errorMessage")) }
}
}
val channel = BroadcastChannel<PurchaseEvent>(1)
}
send
to sendBlocking
and test was easylouiscad
09/06/2018, 3:51 PM