-
Notifications
You must be signed in to change notification settings - Fork 26
/
BBlock.m
65 lines (54 loc) · 1.87 KB
/
BBlock.m
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
//
// BBlock.m
// BBlock
//
// Created by David Keegan on 4/10/12.
// Copyright (c) 2012 David Keegan. All rights reserved.
//
#import "BBlock.h"
@implementation BBlock
+ (void)dispatchOnMainThread:(void (^)())block{
NSParameterAssert(block != nil);
dispatch_async(dispatch_get_main_queue(), block);
}
+ (void)dispatchAfter:(NSTimeInterval)delay onMainThread:(void (^)())block{
NSParameterAssert(block != nil);
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delay*NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), block);
}
+ (void)dispatchOnSynchronousQueue:(void (^)())block{
NSParameterAssert(block != nil);
static dispatch_queue_t queue;
static dispatch_once_t once;
dispatch_once(&once, ^{
queue = dispatch_queue_create("bblock.queue.serial", DISPATCH_QUEUE_SERIAL);
});
if(queue){
dispatch_async(queue, block);
}
}
+ (void)dispatchOnSynchronousFileQueue:(void (^)())block{
NSParameterAssert(block != nil);
static dispatch_queue_t queue;
static dispatch_once_t once;
dispatch_once(&once, ^{
queue = dispatch_queue_create("bblock.queue.serial.file", DISPATCH_QUEUE_SERIAL);
});
if(queue){
dispatch_async(queue, block);
}
}
+ (void)dispatchOnDefaultPriorityConcurrentQueue:(void (^)())block{
[self dispatchOnConcurrentQueue:DISPATCH_QUEUE_PRIORITY_DEFAULT withBlock:block];
}
+ (void)dispatchOnLowPriorityConcurrentQueue:(void (^)())block{
[self dispatchOnConcurrentQueue:DISPATCH_QUEUE_PRIORITY_LOW withBlock:block];
}
+ (void)dispatchOnHighPriorityConcurrentQueue:(void (^)())block{
[self dispatchOnConcurrentQueue:DISPATCH_QUEUE_PRIORITY_HIGH withBlock:block];
}
+ (void)dispatchOnConcurrentQueue:(long)queue withBlock:(void (^)())block{
NSParameterAssert(block != nil);
dispatch_async(dispatch_get_global_queue(queue, 0), block);
}
@end