Created
February 27, 2019 11:24
-
-
Save pavlospt/9ff789da0367f23c31e9454426684a62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskObservable<T>(private val task: Task<T>) : ObservableOnSubscribe<T> { | |
override fun subscribe(emitter: ObservableEmitter<T>) { | |
task | |
.addOnSuccessListener { t -> | |
if (!emitter.isDisposed) { | |
emitter.onNext(t) | |
emitter.onComplete() | |
} | |
} | |
.addOnFailureListener { e -> | |
if (!emitter.isDisposed) { | |
emitter.onError(e) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment