单军华
2018-04-20 2197e837490f5083d18d9fdb97265d1e0f04832a
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
//
//  GCDGroup.m
//  GCD
//
//  http://home.cnblogs.com/u/YouXianMing/
//  https://github.com/YouXianMing
//
//  Created by XianMingYou on 15/3/15.
//  Copyright (c) 2015年 XianMingYou. All rights reserved.
//
 
#import "GCDGroup.h"
 
@interface GCDGroup ()
 
@property (strong, nonatomic, readwrite) dispatch_group_t dispatchGroup;
 
@end
 
@implementation GCDGroup
 
- (instancetype)init {
    
    self = [super init];
    
    if (self) {
        
        self.dispatchGroup = dispatch_group_create();
    }
    
    return self;
}
 
- (void)enter {
    
    dispatch_group_enter(self.dispatchGroup);
}
 
- (void)leave {
    
    dispatch_group_leave(self.dispatchGroup);
}
 
- (void)wait {
    
    dispatch_group_wait(self.dispatchGroup, DISPATCH_TIME_FOREVER);
}
 
- (BOOL)wait:(int64_t)delta {
    
    return dispatch_group_wait(self.dispatchGroup, dispatch_time(DISPATCH_TIME_NOW, delta)) == 0;
}
 
@end