블록을 현재 대기열의 끝에 추가하고 대기열의 기존 항목이 모두 호출 된 후에이 블록이 호출되도록 할 수 있습니까?이전의 모든 대기열 항목이 완료 될 때까지 블록 실행 금지
아래 코드는 작동하지 않습니다
- (void)someTaskWillBeDoneOnThisThreadLater {
// The current scope is a delegate method of a library I'm using,
// and unfortunately the required task gets executed after this delegate
// method is called.
// wait for current queue to be done with everything, including the current scope
dispatch_async(dispatch_get_current_queue(), ^{
// After everything is done, then call the main thread
dispatch_async(dispatch_get_main_queue(), ^{
// Perform some task on main thread
});
});
}
편집 : 다음 코드는 문제를 해결하지만, 난 정말 일초 지연에 의존하지 않으려는
. 나는 오히려 더 나은 해결책을 찾는다. dispatch_barrier_async
문서에서
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
sleep(1);
// Perform something on main thread
});
});
어떤 종류의 대기열에 대해 이야기하고 있습니까? 직렬 대기열에서 작동해야하므로 동시에 하나의 대기열을 확보 할 수 있습니까? – Tommy
정말 확신 할 수 없다.이 프레임 워크의 소스 코드에 액세스 할 수 없다. – aryaxt