forked from cheesemaker/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUUTimer.h
More file actions
66 lines (46 loc) · 1.97 KB
/
UUTimer.h
File metadata and controls
66 lines (46 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// UUTimer.h
// Useful Utilities - GCD based timer
//
// License:
// You are free to use this code for whatever purposes you desire. The only
// requirement is that you smile everytime you use it.
//
#import <Foundation/Foundation.h>
@class UUTimer;
typedef void (^UUTimerBlock)(UUTimer* _Nonnull timer);
@interface UUTimer : NSObject
@property (nonnull, nonatomic, copy, readonly) NSString* timerId;
@property (nullable, nonatomic, strong, readonly) id userInfo;
- (nonnull id) initWithInterval:(NSTimeInterval)interval
userInfo:(nullable id)userInfo
repeat:(BOOL)repeat
queue:(nonnull dispatch_queue_t)queue
block:(nonnull UUTimerBlock)block;
- (nonnull id) initWithId:(nonnull NSString*)timerId
interval:(NSTimeInterval)interval
userInfo:(nullable id)userInfo
repeat:(BOOL)repeat
queue:(nonnull dispatch_queue_t)queue
block:(nonnull UUTimerBlock)block;
- (void) start;
- (void) cancel;
// Returns a shared serial queue for executing timers on a background thread
+ (nonnull dispatch_queue_t) backgroundTimerQueue;
// Alias for dispatch_get_main_queue()
+ (nonnull dispatch_queue_t) mainThreadTimerQueue;
// Find an active timer by its ID
+ (nullable instancetype) findActiveTimer:(nonnull NSString*)timerId;
// Lists all active timers
+ (nonnull NSArray<UUTimer*>*) listActiveTimers;
@end
@interface UUTimer (WatchdogTimers)
// Cancels any existing timer with this ID, and kicks off a new timer
// on the background timer queue. If the timeout value is negative, the
// new timer will not be started.
+ (void) startWatchdogTimer:(nonnull NSString*)timerId
timeout:(NSTimeInterval)timeout
userInfo:(nullable id)userInfo
block:(nonnull void (^)(id _Nullable userInfo))block;
+ (void) cancelWatchdogTimer:(nonnull NSString*)timerId;
@end