Latest | 1.0.4 |
---|---|
Homepage | https://github.com/lyandy/AndyGCD |
License | MIT |
Platforms | ios 8.0, requires ARC |
Frameworks | Foundation |
Authors |
AndyGCD aimed to make C GCD easier and simpler to use. Include dispatchQueue、delay、group、timer、semaphore、apply、barrier.
Use in pod: pod 'AndyGCD'
dispatchQueue
[AndyGCDQueue executeInGlobalQueue:^{
NSLog(@"---%@", [NSThread currentThread]);
[AndyGCDQueue executeInMainQueue:^{
NSLog(@"---%@", [NSThread currentThread]);
}];
}];
delay
[AndyGCDQueue executeInGlobalQueue:^{
NSLog(@"---%@", [NSThread currentThread]);
[AndyGCDQueue executeInMainQueue:^{
NSLog(@"---%@", [NSThread currentThread]);
} afterDelaySecs:3];
} afterDelaySecs:3];
group
AndyGCDGroup *group = [[AndyGCDGroup alloc] init];
[[AndyGCDQueue globalQueue] execute:^{
NSLog(@"---%@", [NSThread currentThread]);
} inGroup:group];
[[AndyGCDQueue globalQueue] execute:^{
NSLog(@"---%@", [NSThread currentThread]);
} inGroup:group];
[[AndyGCDQueue mainQueue] notify:^{
NSLog(@"---%@", [NSThread currentThread]);
} inGroup:group];
timer
self.timer = [[AndyGCDTimer alloc] initInQueue:[AndyGCDQueue mainQueue]];
[self.timer timerExecute:^{
NSLog(@"---%@", [NSThread currentThread]);
} timeInterval:NSEC_PER_SEC * 3 delay:NSEC_PER_SEC * 3];
[self.timer start];
semaphore
AndyGCDSemaphore *semaphore = [[AndyGCDSemaphore alloc] init];
[AndyGCDQueue executeInGlobalQueue:^{
NSLog(@"---%@", [NSThread currentThread]);
[semaphore wait];
}];
[AndyGCDQueue executeInGlobalQueue:^{
NSLog(@"---%@", [NSThread currentThread]);
[semaphore signal];
}];
apply
NSString *from = @"/Users/liyang/Desktop/From";
NSString *to = @"/Users/liyang/Desktop/To";
NSFileManager *mgr = [NSFileManager defaultManager];
NSArray *subpaths = [mgr subpathsAtPath:from];
[[AndyGCDQueue globalQueue] applyExecute:subpaths.count block:^(size_t index) {
NSString *subpath = subpaths[index];
NSString *fromFullpath = [from stringByAppendingPathComponent:subpath];
NSString *toFullpath = [to stringByAppendingPathComponent:subpath];
// cut
[mgr moveItemAtPath:fromFullpath toPath:toFullpath error:nil];
NSLog(@"%@---%@", [NSThread currentThread], subpath);
}];
barrier
_注意 dispatch_get_global_queue(<#long identifier#>, <#unsigned long flags#>)
是不行的。即在使用barrier的时候不可以使用[AndyGCDQueue globalQueue]
全局队列_
AndyGCDQueue *concurrentQueue = [[AndyGCDQueue alloc] initConcurrent];
[concurrentQueue execute:^{
NSLog(@"----1-----%@", [NSThread currentThread]);
}];
[concurrentQueue execute:^{
NSLog(@"----2-----%@", [NSThread currentThread]);
}];
[concurrentQueue barrierExecute:^{
NSLog(@"----barrier-----%@", [NSThread currentThread]);
}];
[concurrentQueue execute:^{
NSLog(@"----3-----%@", [NSThread currentThread]);
}];
[concurrentQueue execute:^{
NSLog(@"----4-----%@", [NSThread currentThread]);
}];
QOS DispatchContextQueue
AndyGCDQueue *contextQueue = [[AndyGCDQueue alloc] initWithQOS:NSQualityOfServiceUtility queueCount:5];
for (int i = 0; i < 100; i++) {
[contextQueue execute:^{
NSLog(@"=====> %@", [NSThread currentThread]);
}];
[contextQueue execute:^{
NSLog(@"=====> %@", [NSThread currentThread]);
}];
[contextQueue execute:^{
NSLog(@"=====> %@", [NSThread currentThread]);
}];
}
Latest podspec
{ "name": "AndyGCD", "version": "1.0.4", "summary": "AndyGCD aimed to make C GCD easier and simpler to use.", "description": "AndyGCD aimed to make C GCD easier and simpler to use. Include dispatchQueueu3001delayu3001groupu3001timeru3001semaphoreu3001applyu3001barrier.", "homepage": "https://github.com/lyandy/AndyGCD", "license": "MIT", "authors": { "u674eu626c": "[email protected]" }, "platforms": { "ios": "8.0" }, "source": { "git": "https://github.com/lyandy/AndyGCD.git", "tag": "1.0.4" }, "source_files": "AndyGCD/**/*", "frameworks": "Foundation", "requires_arc": true }
Sat, 16 Mar 2019 11:25:06 +0000