ReactiveCocoa recurring signalAsk Question


I have the following code:

- (RACSignal *)addSyncTask:(RACSignal *)task withInterval:(NSTimeInterval)interval
    return [[task concat:[[RACSignal empty] delay:interval]] then:^RACSignal *{
        return [self addSyncTask:task withInterval:interval];

- (void)setupFooSync
    RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        [self.API syncFooWithCompletion:^(id response, NSError *error) {
            [subscriber sendError:error];
            [subscriber sendCompleted];
        return nil;
    [self addSyncTask:signal withInterval:60];

The idea is that once setupFooSync is invoked, the sync will occur once every 60 seconds until the containing instance is deallocated. However, with the code above, the sync never occurs. When I change +createSignal: to +startLazilyWithScheduler:, it occurs only once. I am guessing that since the same sync signal is being reused every time, there needs to be some sort of reset. Any pointers would be greatly appreciated.


It seems that concat doesn't trigger the needed subscribe method, try this instead:

[[[task then:^RACSignal *{
    return [[RACSignal interval:5 onScheduler:[RACScheduler mainThreadScheduler]] take:1];
}] repeat] subscribeCompleted:^{

标签: objective-c reactive-cocoa
© 2014 TuiCode, Inc.