0

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?

7ynk3r
  • 958
  • 13
  • 17
  • 1
    The thing that you're asking seems a little contradictory. If the signals have side effects, and they're run in parallel, it doesn't make sense to say "stop everyone else" as soon as one has an error, because any permutation of the other signals could have completed already. Because you aren't guaranteeing the order, there's no way to know *which* side effects have occurred at the time that any of them error out. – Ian Henry Apr 11 '14 at 20:50
  • Is my question "Which is the proper way to parallelize two signals, taking into account that if some of them fails, the rest will be automatically disposed?", I don't think so. Anyway, talking a about the side effects, I really want to cancel all the others as soon as one fails, because I can use a "catch" to clean all the side effects an retry later. But, as is in this case the other signals keeps running after the error (after a catch also), making its side effect and polluting my data structure. – 7ynk3r Apr 12 '14 at 02:57

0 Answers0