From a6dcb234c12e9443ef56c4db0420dbcb398730df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Pin=CC=83era=20Buendi=CC=81a?= Date: Tue, 5 Apr 2016 10:13:30 +0200 Subject: [PATCH] Reactive operations also support throwing errors --- .../ReactiveStorage+ReactiveCocoa.swift | 24 +++++++++---------- .../Reactive/Rx/ReactiveStorage+Rx.swift | 18 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/SugarRecord/Source/Reactive/ReactiveCocoa/ReactiveStorage+ReactiveCocoa.swift b/SugarRecord/Source/Reactive/ReactiveCocoa/ReactiveStorage+ReactiveCocoa.swift index 8ba72be7..e68c35b8 100644 --- a/SugarRecord/Source/Reactive/ReactiveCocoa/ReactiveStorage+ReactiveCocoa.swift +++ b/SugarRecord/Source/Reactive/ReactiveCocoa/ReactiveStorage+ReactiveCocoa.swift @@ -6,11 +6,11 @@ public extension Storage { // MARK: - Operation - func rac_operation(op: (context: Context, save: () -> Void) -> Void) -> SignalProducer { + func rac_operation(op: (context: Context, save: () -> Void) throws -> Void) -> SignalProducer { return SignalProducer { (observer, disposable) in do { - try self.operation { (context, saver) in - op(context: context, save: { + try self.operation { (context, saver) throws in + try op(context: context, save: { saver() }) observer.sendCompleted() @@ -22,20 +22,20 @@ public extension Storage { } } - func rac_operation(op: (context: Context) -> Void) -> SignalProducer { - return self.rac_operation { (context, saver) in - op(context: context) + func rac_operation(op: (context: Context) throws -> Void) -> SignalProducer { + return self.rac_operation { (context, saver) throws in + try op(context: context) saver() } } - func rac_backgroundOperation(op: (context: Context, save: () -> Void) -> Void) -> SignalProducer { + func rac_backgroundOperation(op: (context: Context, save: () -> Void) throws -> Void) -> SignalProducer { return SignalProducer { (observer, disposable) in let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT dispatch_async(dispatch_get_global_queue(priority, 0)) { do { - try self.operation { (context, saver) in - op(context: context, save: { + try self.operation { (context, saver) throws in + try op(context: context, save: { saver() }) observer.sendCompleted() @@ -48,9 +48,9 @@ public extension Storage { } } - func rac_backgroundOperation(op: (context: Context) -> Void) -> SignalProducer { - return rac_backgroundOperation { (context, save) in - op(context: context) + func rac_backgroundOperation(op: (context: Context) throws -> Void) -> SignalProducer { + return rac_backgroundOperation { (context, save) throws in + try op(context: context) save() } } diff --git a/SugarRecord/Source/Reactive/Rx/ReactiveStorage+Rx.swift b/SugarRecord/Source/Reactive/Rx/ReactiveStorage+Rx.swift index f0b2292b..f0d5c9b1 100644 --- a/SugarRecord/Source/Reactive/Rx/ReactiveStorage+Rx.swift +++ b/SugarRecord/Source/Reactive/Rx/ReactiveStorage+Rx.swift @@ -3,11 +3,11 @@ import RxSwift public extension Storage { - func rx_operation(op: (context: Context, save: () -> Void) -> Void) -> Observable { + func rx_operation(op: (context: Context, save: () -> Void) throws -> Void) -> Observable { return Observable.create { (observer) -> RxSwift.Disposable in do { - try self.operation { (context, saver) -> Void in - op(context: context, save: { () -> Void in + try self.operation { (context, saver) throws -> Void in + try op(context: context, save: { () -> Void in saver() }) observer.onCompleted() @@ -27,11 +27,11 @@ public extension Storage { } } - func rx_backgroundOperation(op: (context: Context, save: () -> Void) -> Void) -> Observable { + func rx_backgroundOperation(op: (context: Context, save: () -> Void) throws -> Void) -> Observable { return Observable.create { (observer) -> RxSwift.Disposable in do { - try self.operation { (context, saver) in - op(context: context, save: { () -> Void in + try self.operation { (context, saver) throws in + try op(context: context, save: { () -> Void in saver() }) observer.onCompleted() @@ -44,9 +44,9 @@ public extension Storage { } } - func rx_backgroundOperation(op: (context: Context) -> Void) -> Observable { - return rx_backgroundOperation { (context, save) in - op(context: context) + func rx_backgroundOperation(op: (context: Context) throws -> Void) -> Observable { + return rx_backgroundOperation { (context, save) throws in + try op(context: context) save() } }