Is there any easy way to debug subscription? #1052

Closed
andrask opened this Issue Jan 8, 2014 · 4 comments

Comments

Projects
None yet
4 participants
@andrask
Contributor

andrask commented Jan 8, 2014

I'm struggling with a piece of code where the subscription seems not to happen on the signal. It would be great to NSLog all attempts in the chain where subscription is happening to figure out where it stops. I'm thinking of something like a

[signal debug]

call where every event is logged from the signal. I already use the doXXX operators but I need something more powerful/automated here.

@jspahrsummers

This comment has been minimized.

Show comment
Hide comment
@jspahrsummers

jspahrsummers Jan 8, 2014

Member

We have -logAll and friends. Does that help?

Member

jspahrsummers commented Jan 8, 2014

We have -logAll and friends. Does that help?

@andrask

This comment has been minimized.

Show comment
Hide comment
@andrask

andrask Jan 8, 2014

Contributor

Thank you, I was looking for a RACSignal+ file. It was hidden in RACSignal. I guess having all interfaces in their own files may be reasonable here. 😕

log* seems not to take care of subscription (which is probably not very useful in many cases), though, so I just wrote my own thing.

-(RACSignal *)debug {
return [[RACSignal createSignal:^(id<RACSubscriber> subscriber) {
    NSLog(@"%@ subscribed %@", self, subscriber);
    return [self subscribeNext:^(id x) {
        NSLog(@"%@ next value=%@", self, x);
        [subscriber sendNext:x];
    } error:^(NSError *error) {
        NSLog(@"%@ error %@", self, error);
        [subscriber sendError:error];
    } completed:^{
        NSLog(@"%@ completed", self);
        [subscriber sendCompleted];
    }];
}] setNameWithFormat:@"%@", self.name];
}
Contributor

andrask commented Jan 8, 2014

Thank you, I was looking for a RACSignal+ file. It was hidden in RACSignal. I guess having all interfaces in their own files may be reasonable here. 😕

log* seems not to take care of subscription (which is probably not very useful in many cases), though, so I just wrote my own thing.

-(RACSignal *)debug {
return [[RACSignal createSignal:^(id<RACSubscriber> subscriber) {
    NSLog(@"%@ subscribed %@", self, subscriber);
    return [self subscribeNext:^(id x) {
        NSLog(@"%@ next value=%@", self, x);
        [subscriber sendNext:x];
    } error:^(NSError *error) {
        NSLog(@"%@ error %@", self, error);
        [subscriber sendError:error];
    } completed:^{
        NSLog(@"%@ completed", self);
        [subscriber sendCompleted];
    }];
}] setNameWithFormat:@"%@", self.name];
}

@andrask andrask closed this Jan 8, 2014

@nikolaykasyanov

This comment has been minimized.

Show comment
Hide comment
@nikolaykasyanov

nikolaykasyanov Jan 9, 2014

Contributor

What about this? But it won't log a subscriber.

- (RACSignal *)debug
{
    return [RACSignal defer:^{
        NSLog(@"Subscribed!);
        return [self logAll];
    }];
}
Contributor

nikolaykasyanov commented Jan 9, 2014

What about this? But it won't log a subscriber.

- (RACSignal *)debug
{
    return [RACSignal defer:^{
        NSLog(@"Subscribed!);
        return [self logAll];
    }];
}
@notxcain

This comment has been minimized.

Show comment
Hide comment
@notxcain

notxcain Jan 9, 2014

+1 for @Corristo answer!

notxcain commented Jan 9, 2014

+1 for @Corristo answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment