Skip to content

Commit

Permalink
修改全局queue 为自定义queue
Browse files Browse the repository at this point in the history
  • Loading branch information
hongru qi committed Aug 3, 2017
1 parent c85d96f commit ab8909e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Example/WTAppLauncher/WTAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSLog(@"WTAppLauncherType_SerialQueue 1");
}];

[launcher addLauncherWithType:WTAppLauncherType_WTGroupQueue block:^{
[launcher addLauncherWithType:WTAppLauncherType_GroupQueue block:^{
sleep(3);
NSLog(@"WTAppLauncherType_WTGroupQueue 1");
}];
Expand All @@ -32,19 +32,19 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSLog(@"WTAppLauncherType_MainThread");
}];

[launcher addLauncherWithType:WTAppLauncherType_GrobalQueue block:^{
[launcher addLauncherWithType:WTAppLauncherType_GlobalQueue block:^{
NSLog(@"WTAppLauncherType_GrobalQueue");
}];

[launcher addLauncherWithType:WTAppLauncherType_WTGroupQueue block:^{
[launcher addLauncherWithType:WTAppLauncherType_GroupQueue block:^{
NSLog(@"WTAppLauncherType_WTGroupQueue 2");
}];

[launcher addLauncherWithType:WTAppLauncherType_SerialQueue block:^{
NSLog(@"WTAppLauncherType_SerialQueue 3 ");
}];

[launcher addNotificaitonGroupQueue:^{
[launcher addNotificationGroupQueue:^{
NSLog(@"addNotificaitonGroupQueue");
}];

Expand Down
2 changes: 1 addition & 1 deletion WTAppLauncher.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'WTAppLauncher'
s.version = '2.0.1'
s.version = '2.1.0'
s.summary = 'App launcher tools'

# This description is used to generate tags and improve search results.
Expand Down
2 changes: 1 addition & 1 deletion WTAppLauncher/Classes/WTAppLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, WTAppLauncherType) {
WTAppLauncherType_WTGroupQueue,
WTAppLauncherType_GroupQueue,
WTAppLauncherType_MainThread,
WTAppLauncherType_GlobalQueue,
WTAppLauncherType_SerialQueue // 串行队列,放入有执行顺序的block
Expand Down
22 changes: 16 additions & 6 deletions WTAppLauncher/Classes/WTAppLauncher.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ - (instancetype)init
{
if (self = [super init]) {
_launchGroup = dispatch_group_create();
_launchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_serialQueue = dispatch_queue_create("com.wtlauncher.queue", NULL);
_launchQueue = dispatch_queue_create("com.wtlauncher.concurrent.queue", DISPATCH_QUEUE_CONCURRENT);
_serialQueue = dispatch_queue_create("com.wtlauncher..serial.queue", NULL);
_launchTime = CACurrentMediaTime();
}

Expand All @@ -40,8 +40,8 @@ - (void)addLauncherWithType:(WTAppLauncherType)type block:(dispatch_block_t)bloc
case WTAppLauncherType_MainThread:
[self asyncRunLaunchInMainThread:block];
break;
case WTAppLauncherType_WTGroupQueue:
[self asyncRunLaunchInXYGroupQueue:block];
case WTAppLauncherType_GroupQueue:
[self asyncRunLaunchInGroupQueue:block];
break;
case WTAppLauncherType_GlobalQueue:
[self asyncRunLaunchInGlobalQueue:block];
Expand All @@ -58,41 +58,51 @@ - (void)endLanuchingWithTimeout:(float)timeout
{
dispatch_time_t groupTimeout = dispatch_time(DISPATCH_TIME_NOW, timeout*NSEC_PER_SEC);
dispatch_group_wait(_launchGroup, groupTimeout);
NSLog(@"launch app time : %g s", CACurrentMediaTime() - self.launchTime);
NSLog(@"launch app end time : %g s", CACurrentMediaTime() - self.launchTime);
}

- (void)asyncRunLaunchInMainThread:(dispatch_block_t) block
{
dispatch_async(dispatch_get_main_queue(), ^{
CFTimeInterval start = CACurrentMediaTime();
block();
NSLog(@"launch asyncRunLaunchInMainThread time : %g s", CACurrentMediaTime() - start);
});
}

- (void)asyncRunLaunchInXYGroupQueue:(dispatch_block_t) block
- (void)asyncRunLaunchInGroupQueue:(dispatch_block_t) block
{
dispatch_group_async(_launchGroup, _launchQueue, ^{
CFTimeInterval start = CACurrentMediaTime();
block();
NSLog(@"launch asyncRunLaunchInGroupQueue time : %g s", CACurrentMediaTime() - start);
});
}

- (void)asyncRunLaunchInGlobalQueue:(dispatch_block_t) block
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
CFTimeInterval start = CACurrentMediaTime();
block();
NSLog(@"launch asyncRunLaunchInGlobalQueue time : %g s", CACurrentMediaTime() - start);
});
}

- (void)syncRunLaunchInSerialQueue:(dispatch_block_t) block
{
dispatch_sync(_serialQueue, ^{
CFTimeInterval start = CACurrentMediaTime();
block();
NSLog(@"launch syncRunLaunchInSerialQueue time : %g s", CACurrentMediaTime() - start);
});
}

- (void)addNotificationGroupQueue:(dispatch_block_t) block
{
dispatch_group_notify(_launchGroup, _launchQueue, ^{
CFTimeInterval start = CACurrentMediaTime();
block();
NSLog(@"launch addNotificationGroupQueue time : %g s", CACurrentMediaTime() - start);
});
}

Expand Down

0 comments on commit ab8909e

Please sign in to comment.