Skip to content

An Objective-C timer that restricts firing to a time range. If it's called BEFORE min, it waits for min. If it's called AFTER max, it's called at max.

License

Notifications You must be signed in to change notification settings

mysterioustrousers/MTTimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MTTimer

An Objective-C timer that restricts firing to a time range. If it's dismissed BEFORE min, it waits for min. If it's dismissed AFTER max, it's called at max.

Developed for Firehose by Mysterious Trousers

Installation

Using CocoaPods, add this line to your Podfile:

pod "MTTimer"

Example

@implementation FMRootWindowView {
	MTTimer *_durationTimer;
}

#pragma mark - Public

- (void)displayLoadingWithMessage:(NSString *)message
{
	...

	// It's kind of jolting to see a loading message pop up and disappear in 
	// just a few miliseconds, in the case of a request that loads very quickly, 
	// so we constrain the timer to not fire until at least 2 seconds, even if
	// `done` is called before that.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:2 untilPerformingBlock:^{
        // do whatever you do when it's done
    }];

    ...
}

- (void)displaySuccessWithMessage:(NSString *)errorMessage
{
	...

	// We want a the success message to show for at least 2 seconds, but we 
	// don't want it showing more than 4.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:2 atMost:4 beforePerformingBlock:^{
        // do whatever you do when it's done
    }];

    ...
}

- (void)displayErrorWithMessage:(NSString *)errorMessage
{
	...
	
	// We want a the error message to show for at least 30 seconds, to make 
	// sure the user sees it.
    _durationTimer = [MTTimer timerThatMustLastAtLeast:30 atMost:35 beforePerformingBlock:^{
        [self animateUp];
    }];

	...
}

- (void)dismissStatus
{
	// This is called whenever your external operation is complete. If `done` is calle BEFORE
	// the min seconds has been reached, the completion block will not fire until min is reached.
	// If you call this AFTER max, the completion block will have already fired when max was reached.
    [_durationTimer done];
}

@end

Contributing

Please update and run the tests before submitting a pull request. Thanks.

Author

Adam Kirk (@atomkirk)

About

An Objective-C timer that restricts firing to a time range. If it's called BEFORE min, it waits for min. If it's called AFTER max, it's called at max.

Resources

License

Stars

Watchers

Forks

Packages

No packages published