subscribe mapping on background queue
This commit is contained in:
parent
dd26a70db0
commit
0348ba613e
|
|
@ -31,7 +31,6 @@ public extension Reactive where Base: Alamofire.SessionManager {
|
|||
/// - Returns: Observable with HTTP URL Response and target object
|
||||
func responseModel<T: ImmutableMappable>(requestParameters: ApiRequestParameters) -> Observable<(HTTPURLResponse, T)> {
|
||||
return apiRequest(requestParameters: requestParameters)
|
||||
.observeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated))
|
||||
.flatMap { $0.rx.apiResponse() }
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +42,6 @@ public extension Reactive where Base: Alamofire.SessionManager {
|
|||
Observable<(HTTPURLResponse, T)> where T.ModelType == T {
|
||||
|
||||
return apiRequest(requestParameters: requestParameters)
|
||||
.observeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated))
|
||||
.flatMap { $0.rx.apiResponse() }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,25 +15,33 @@ public extension Reactive where Base: DataRequest {
|
|||
|
||||
/// Method which serializes response into target object
|
||||
///
|
||||
/// - Parameter mappingQueueQoS: QoS of underlying scheduler queue on which mapping will be executed
|
||||
/// - Returns: Observable with HTTP URL Response and target object
|
||||
func apiResponse<T: ImmutableMappable>() -> Observable<(HTTPURLResponse, T)> {
|
||||
return responseJSON().map { resp, value in
|
||||
let json = try cast(value) as [String: Any]
|
||||
func apiResponse<T: ImmutableMappable>(mappingQueueQoS: DispatchQoS = .default) -> Observable<(HTTPURLResponse, T)> {
|
||||
return responseJSON()
|
||||
.map { resp, value in
|
||||
let json = try cast(value) as [String: Any]
|
||||
|
||||
return (resp, try T(JSON: json))
|
||||
}
|
||||
return (resp, try T(JSON: json))
|
||||
}
|
||||
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: mappingQueueQoS))
|
||||
}
|
||||
|
||||
/// Method which serializes response into target object
|
||||
///
|
||||
/// - Parameter mappingQueueQoS: QoS of underlying scheduler queue on which mapping will be executed
|
||||
/// - Returns: Observable with HTTP URL Response and target object
|
||||
func apiResponse<T: ObservableMappable>() -> Observable<(HTTPURLResponse, T)> where T.ModelType == T {
|
||||
return responseJSON().flatMap { resp, value -> Observable<(HTTPURLResponse, T)> in
|
||||
let json = try cast(value) as [String: Any]
|
||||
func apiResponse<T: ObservableMappable>(mappingQueueQoS: DispatchQoS = .default) -> Observable<(HTTPURLResponse, T)>
|
||||
where T.ModelType == T {
|
||||
|
||||
return T.createFrom(map: Map(mappingType: .fromJSON, JSON: json))
|
||||
.map { (resp, $0) }
|
||||
}
|
||||
return responseJSON()
|
||||
.flatMap { resp, value -> Observable<(HTTPURLResponse, T)> in
|
||||
let json = try cast(value) as [String: Any]
|
||||
|
||||
return T.createFrom(map: Map(mappingType: .fromJSON, JSON: json))
|
||||
.map { (resp, $0) }
|
||||
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: mappingQueueQoS))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue