diff --git a/Sources/RxMoya-ModelMapper/Single+ModelMapper.swift b/Sources/RxMoya-ModelMapper/Single+ModelMapper.swift index 82b1148..c546770 100644 --- a/Sources/RxMoya-ModelMapper/Single+ModelMapper.swift +++ b/Sources/RxMoya-ModelMapper/Single+ModelMapper.swift @@ -21,54 +21,46 @@ extension PrimitiveSequence where TraitType == SingleTrait, ElementType == Respo /// implements the Mappable protocol and returns the result back on the MainScheduler. /// If the conversion fails, the signal errors. public func map(to type: T.Type, keyPath: String? = nil) -> Single { - return observeOn(ConcurrentDispatchQueueScheduler(qos: .background)) - .flatMap { response -> Single in + return flatMap { response -> Single in return Single.just(try response.map(to: type, keyPath: keyPath)) - } - .observeOn(MainScheduler.instance) + } } - + /// Maps data received from the signal into an array of objects (on the default Background thread) /// which implement the Mappable protocol and returns the result back on the MainScheduler /// If the conversion fails, the signal errors. public func map(to type: [T].Type, keyPath: String? = nil) -> Single<[T]> { - return observeOn(ConcurrentDispatchQueueScheduler(qos: .background)) - .flatMap { response -> Single<[T]> in + return flatMap { response -> Single<[T]> in return Single.just(try response.map(to: type, keyPath: keyPath)) - } - .observeOn(MainScheduler.instance) + } } - + /// Maps data received from the signal into an object (on the default Background thread) which /// implements the Mappable protocol and returns the result back on the MainScheduler. /// If the conversion fails, the nil is returned instead of error signal. public func mapOptional(to type: T.Type, keyPath: String? = nil) -> Single { - return observeOn(ConcurrentDispatchQueueScheduler(qos: .background)) - .flatMap { response -> Single in + return flatMap { response -> Single in do { let object = try response.map(to: type, keyPath: keyPath) return Single.just(object) } catch { return Single.just(nil) } - - } - .observeOn(MainScheduler.instance) + } } - + /// Maps data received from the signal into an array of objects (on the default Background thread) /// which implement the Mappable protocol and returns the result back on the MainScheduler /// If the conversion fails, the nil is returned instead of error signal. public func mapOptional(to type: [T].Type, keyPath: String? = nil) -> Single<[T]?> { - return observeOn(ConcurrentDispatchQueueScheduler(qos: .background)) - .flatMap { response -> Single<[T]?> in + return flatMap { response -> Single<[T]?> in do { let object = try response.map(to: type, keyPath: keyPath) return Single.just(object) } catch { return Single.just(nil) } - } - .observeOn(MainScheduler.instance) + } } } +