首先发送完成或错误的RACSignals数组

时间:2014-02-28 13:37:12

标签: reactive-cocoa racsignal

我确定有一种更简单的方法吗?或者它已经存在?

+ (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;
    }];
}

1 个答案:

答案 0 :(得分:1)

不,目前没有一个运营商表现那样。这就像+merge:+zip:之间的交叉。