Question

I'm sure there's an easier way? Or that it already exists?

+ (RACSignal *)totallyCombinedSignalOfSignals:(NSArray *)signals
{    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {

        RACCompoundDisposable *compoundDisposable = [RACCompoundDisposable compoundDisposable];

        for(RACSignal *signal in signals)
        {
            RACDisposable *disposable = [signal subscribe:subscriber];
            [compoundDisposable addDisposable:disposable];
        }

        return compoundDisposable;
    }];
}

Usecase

/// Finite signal which either sends completed or error
- (RACSignal *)signalCanRenderPage
{
    return [[self class] totallyCombinedSignalOfSignals:
            @[[self finiteSignalDocumentReady], // sends completed
              [self finiteSignalTimeOutWithInterval:20], // sends error
              [self finiteSignalDocumentNeedsToBeReloaded]] // sends error
            ];
}

- (RACSignal *)signalRenderPageWithJSONString:(NSString *)pageJSON
                                assetsBaseUrl:(NSString *)assetsBaseUrl
{
    @weakify(self);
    const NSTimeInterval timeOutInterval = 20;
    return [[self signalCanRenderPage] then:^RACSignal *{
        @strongify(self);

        RACSignal *signal = ...;

        return signal;
    }];
}
Was it helpful?

Solution

No, there isn't currently an operator that behaves that way. It's like a cross between +merge: and +zip:.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top