Skip to content

Instantly share code, notes, and snippets.

@fuwaneko
Created September 25, 2015 14:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuwaneko/e17fa7708ca43afe609f to your computer and use it in GitHub Desktop.
Save fuwaneko/e17fa7708ca43afe609f to your computer and use it in GitHub Desktop.
Kotlin wrapper example
private fun wrap<T>(listener: (ISyncService) -> Observable<T>): Observable<T> {
val subject: PublishSubject<T> = PublishSubject.create()
val combo = syncServiceSubject.subscribe({ service ->
try {
listener(service).subscribe { result ->
subject.onNext(result)
}
} catch (e: RemoteException) {
subject.onError(e)
}
}, { throwable ->
subject.onError(throwable)
})
compositeSubscription.add(combo)
return subject.asObservable()
}
override fun signin(phone: String, password: String): Observable<Token> {
return wrap { service ->
service.signin(phone, password)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment