Skip to content

Instantly share code, notes, and snippets.

@pavlospt
Created February 27, 2019 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavlospt/9ff789da0367f23c31e9454426684a62 to your computer and use it in GitHub Desktop.
Save pavlospt/9ff789da0367f23c31e9454426684a62 to your computer and use it in GitHub Desktop.
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