Skip to content

Instantly share code, notes, and snippets.

@fuwaneko
Created Sep 25, 2015
Embed
What would you like to do?
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