-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No ability to inject own scheduler #51
Comments
Hi @ivanmkc. You are right, it is a bug on my end. I removed the |
Hi, I went with a solution in my fork that injected the scheduler into the function. However, it breaks existing code and I'm not sure what RxSwift guidelines suggest to do in this case. Are you saying that developers using your library should handle the schedulers themselves when they call the map function (as in the alternative solution below)? My current fork's solution: public func map<T: Mappable>(to type: T.Type, scheduler: SchedulerType, keyPath: String? = nil) -> Single<T> {
return self.observeOn(scheduler)
.flatMap { response -> Single<T> in
return Single.just(try response.map(to: type, keyPath: keyPath))
}
} Alternative solution: public func map<T: Mappable>(to type: T.Type, scheduler: SchedulerType, keyPath: String? = nil) -> Single<T> {
return flatMap { response -> Single<T> in
return Single.just(try response.map(to: type, keyPath: keyPath))
}
} and at the call site: return provider
.rx
.request(targetType)
.observeOn(mappingScheduler)
.map(to: T.self)
.asObservable() |
@ivanmkc Yeah, I think that developers should handle switching between schedulers themselves (your alternative solution). |
Ok, I tried to search for some RxSwift guideline on where it states this what couldn't find anything. I will submit a PR with the alternative. Thanks! |
Submitted a PR. |
@ivanmkc there is no strict rule for managing schedulers in external libraries (as far as I know), so this is probably left out to developers. |
I'm using RxTest to test my network services which makes use of a virtual time TestScheduler. However, in Single+ModelMapper, you have fixed schedulers which are incompatible with RxTest as they would have to be replaced by the TestScheduler for unit tests. Similar discussion is here: ReactiveX/RxSwift#1100
Fix would be to do dependency injection of schedulers, perhaps with a default value.
Problematic code here:
The text was updated successfully, but these errors were encountered: