as we know main_queue is a serial queue。There is no real async。
- (void)someMethod{
dispatch_async(dispatch_get_main_queue(),^{
NSLog(@"main_async invoke");
});
NSLog(@"method invoke");
}
the code above "method invoke" will be write before "main_async invoke"。because in main_queue there is no real async. but the code bellow may sai NO:
- (void)someMethod{
__block BOOL flag=YES;
NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"blockOperation invoke");
[NSThread sleepForTimeInterval:4];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"main_async invoke");
flag=NO;
});
}];
[blockOperation start];
while (flag) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
}
NSLog(@"method invoke");
}
the code above "method invoke" will be write after "main_async invoke" I think it's because of the 'RunLoop'.Is there anyone can explain that's why?