calimarkus/JDFlipNumberView

Nested completion blocks aren't working

calimarkus opened this issue · 1 comments

Discussion with MattFoley@dcdbd01

I'm sorry, this is a bit in progress on my fork and didn't have time to fully fix it. The starting issue, an infinite loop, was caused calling something like:

[self.countdownView animateToValue:someValue duration:someDuration  completion:^(BOOL finished) {
    [self.countdownView animateToValue:someValue duration:someDuration completion:^(BOOL finished) {
        if (finished) {
            [self doStuff];
        }
    }];
}];

The first line of animateToValue called [self stopAnimation] would try to call the previous completion block, which executed the second animateToValue, which would hit the [self stopAnimation] again, on and on forever.

You can see in my fork I started to try to fix it but wasn't able to fully fix it before I ran out of time.

My current workaround is this:

[self.countdownView animateToValue:someValue duration:someDuration  completion:^(BOOL finished) {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.flipNumberView animateToValue:someValue duration:someDuration completion:^(BOOL finished) {
            if (finished) {
                [self doStuff];
            }
        }];
    });
}];

I believe the timer issue was just a nested block/threading issue as a result of some of the other changes I've made.

CC: @MattFoley

@MattFoley fixed it today!