典型的なdispatch_async
実行では:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// ...
dispatch_async(dispatch_get_main_queue(), ^{
// ...
});
});
実行中のブロックのみを制限するには、次のようにします。
if (_loadingFromServer) return;
_loadingFromServer = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// ...
dispatch_async(dispatch_get_main_queue(), ^{
// ...
_loadingFromServer = NO;
});
});
フラグを使用せずに、非同期ブロックが実行されている場所を確認する方法はありますか?_loadingFromServer
dispatch_queue_set_specific
この場合に役立ちますか?