This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCDUtils.h
73 lines (61 loc) · 2.08 KB
/
GCDUtils.h
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
65
66
67
68
69
70
71
72
73
//
// GCDUtils.h
// beCherry
//
// Created by Sébastien Orban on 2/05/12.
// Copyright (c) 2012 Random Mechanicals. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
GCD Utils class — various GCD help function, here to simplify and speed the
process of using recurring function.
*/
@interface GCDUtils : NSObject
/**
Will initialize a simple timer the GCD way.
Timer is started after being created, and is always put on the DISPATCH_QUEUE_PRIORITY_HIGH
@param beginningTime when to start the timer. With a zero (or now) value, will
execute immediately the block.
@param repeatTime when to repeat it. With a value of 0 it will cancel itself to prevent unwanted loop
@param queue on which queue to execute this timer. Accept serial and concurrent queue, but will always be executed with dispatch_async;
@param job the block which will be executed
@return the initialized timer
*/
+(dispatch_source_t) timerBeginAt:(dispatch_time_t) beginningTime repeatEvery:(dispatch_time_t) repeatTime withQueue:(dispatch_queue_t) queue doing:(void(^)()) job;
@end
/**
GCD timer class — added to be easily embedded in collections class. As a general
rule, to not fall in compromise state, use the method to handle the timer. Some
behavior with the suspend/resume/cancel state for dispatch source are clearly
undefine.
*/
@interface GCDTimer : NSObject {
dispatch_source_t timer;
BOOL state;
}
/**
Init the timer and launch the timer.
@param beginningTime when to start the timer. With a zero (or now) value, will
execute immediately the block.
@param repeatTime when to repeat it.
@param queue on which queue to execute this timer. Accept serial and concurrent queue
@param task the block which will be executed
@return self
*/
-(id) initTimerAt:(dispatch_time_t) beginningTime
repeatEvery:(dispatch_time_t) repeatTime
withQueue: (dispatch_queue_t) queue
doingTask:(void(^)()) task;
/**
Start the timer.
*/
-(void) startTimer;
/**
Stop the timer.
*/
-(void) stopTimer;
/**
Return the state of the timer, activated or not
*/
-(BOOL) timerState;
@end