Skip to content

Instantly share code, notes, and snippets.

@Gnzlt
Created October 2, 2018 11:33
Show Gist options
  • Select an option

  • Save Gnzlt/4e66c7f6f28db34995d4da2a71ff779d to your computer and use it in GitHub Desktop.

Select an option

Save Gnzlt/4e66c7f6f28db34995d4da2a71ff779d to your computer and use it in GitHub Desktop.
RxJava2 Single extension function to convert Google Play Service Task
package com.example
import com.google.android.gms.tasks.Task
import io.reactivex.Single
fun <TResult> Task<TResult>.toSingle(): Single<TResult> =
Single.create<TResult> { emitter ->
addOnSuccessListener { result -> emitter.onSuccess(result) }
addOnFailureListener { error -> emitter.onError(error) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment