I have the following signal, that I want to parallelize. I'm interested to know when the two signals inside "then" were finished.
[[[[RACSignal empty]
then:^{
return [RACSignal defer:^{
NSLog(@"error");
return [RACSignal error:nil];
}];
}]
then:^{
return [RACSignal defer:^{
NSLog(@"result");
return [RACSignal return:@"1"];
}];
}]
subscribeError:^(NSError *error){
NSLog(error);
}
completed:^{
NSLog(@"completed");
}];
Trying to do so, I created a signal merging the two. As first sight it works but is not really equal to the first one.
[[[RACSignal empty]
then:^{
return [RACSignal merge:@[
[RACSignal defer:^{
NSLog(@"error");
return [RACSignal error:nil];
}],
[RACSignal defer:^{
NSLog(@"result");
return [RACSignal return:@"1"];
}],
]];
}]
subscribeError:^(NSError *error){
NSLog(error);
}
completed:^{
NSLog(@"completed");
}];
You can see that all signals inside merge got evaluated even though there was an error. In my particular case this is a problem because the signals can contain side effects.
Which is the proper way to parallelize two signals, taking into account that if some of them fails, the rest will be automatically disposed?