Skip to content

Commit

Permalink
Fix a regression in the preceeding regresion fix for hs.timer. We now…
Browse files Browse the repository at this point in the history
… store the requested interval in HSTimer since NSTimer can't reliably tell us what it is/was
  • Loading branch information
cmsj committed Nov 16, 2016
1 parent 22e0dcf commit f1936fe
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions extensions/timer/internal.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface HSTimer : NSObject
@property int fnRef;
@property BOOL continueOnError;
@property BOOL repeats;
@property NSTimeInterval interval;

- (void)create:(NSTimeInterval)interval repeat:(BOOL)repeat;
- (void)callback:(NSTimer *)timer;
Expand Down Expand Up @@ -53,7 +54,7 @@ - (void)callback:(NSTimer *)timer {
if (!self.continueOnError) {
// some details about the timer to help identify which one it is:
[skin logBreadcrumb:@"hs.timer callback failed. The timer has been stopped to prevent repeated notifications of the error."];
[skin logBreadcrumb:[NSString stringWithFormat:@" timer details: %s repeating, every %f seconds, next scheduled at %@", CFRunLoopTimerDoesRepeat((__bridge CFRunLoopTimerRef)timer) ? "is" : "is not", timer.timeInterval, timer.fireDate]];
[skin logBreadcrumb:[NSString stringWithFormat:@" timer details: %s repeating, every %f seconds, next scheduled at %@", CFRunLoopTimerDoesRepeat((__bridge CFRunLoopTimerRef)timer) ? "is" : "is not", self.interval, timer.fireDate]];
[self.t invalidate];
}
}
Expand All @@ -66,10 +67,10 @@ - (BOOL)isRunning {
- (void)start {
if (!self.t.isValid) {
// We've previously been stopped, which means the NSTimer is invalid, so recreate it
[self create:self.t.timeInterval repeat:self.repeats];
[self create:self.interval repeat:self.repeats];
}

[self setNextTrigger:self.t.timeInterval];
[self setNextTrigger:self.interval];
[[NSRunLoop currentRunLoop] addTimer:self.t forMode:NSDefaultRunLoopMode];
}

Expand Down Expand Up @@ -104,6 +105,7 @@ - (void)trigger {
timer.fnRef = callbackRef;
timer.continueOnError = continueOnError;
timer.repeats = repeat;
timer.interval = interval;
[timer create:interval repeat:repeat];

return timer;
Expand Down

0 comments on commit f1936fe

Please sign in to comment.