whydna / NSObject-RateLimiting

Rate Limiting (debounce, throttle) category for Objective-C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rate Limiting Categories for Objective-C

Summary

Adds 2 category methods to NSObject to support rate limiting to method calls:

- (void)throttle:(nonnull SEL)action withObject:(nullable id)object duration:(NSTimeInterval)duration;

- (void)debounce:(nonnull SEL)action withObject:(nullable id)object duration:(NSTimeInterval)duration;

For a visual explaination of the differences between throttling and debouncing, see this demo.

Usage Example:

#import "NSObject+RateLimiting.h"

...

[anyObject throttle:@selector(methodToRateLimit) withObject:nil duration:0.1f];

// or

[anyObject debounce:@selector(methodToRateLimit) withObject:nil duration:0.1f];

About

Rate Limiting (debounce, throttle) category for Objective-C


Languages

Language:Objective-C 100.0%