return [RACSignal create:^(id <RACSubscriber> subscriber) {
if (someError) {
[subscriber sendError:documentCreationError];
return;
}
[subscriber sendNext:nil];
[subscriber sendCompleted];
}];
Given the example above, is the return; necessary after sending the subscriber an error, or does execution within this block stop immediately?
Given the example above, is the return; necessary after sending the subscriber an error, or does execution within this block stop immediately?
Given the exact example code above, the return is not necessary. But it's not true that execution within this block stops immediately. It's much safer to use the return, in case you or someone else later adds some code that may have a side effect:
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
if (someError) {
[subscriber sendError:documentCreationError];
}
// This message will be printed even if an error is sent above:
NSLog(@"Do something that could have side effects.");
[subscriber sendNext:nil];
[subscriber sendCompleted];
return nil;
}];
(This is why it's better to keep side effects out of signals, but it's impossible to enforce this with Obj-C and ReactiveCocoa.)
Looks like you're safe not to return, technically. After erring out, RACSubscriber (assuming this is subscribed via subscribeNext: and/or the subscription mechanics match this, which is probably safe), the subscription disposes of itself, which will lead to clearing out the next, error, and completion blocks. So you should be fine without the return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With