我确定有更简单的方法吗?或者它已经存在?
+ (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;
}];
}
用例
/// 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;
}];
}