Cocoa Non-Blocking sleep wait background task
If you have some async task running in background, and you need wait this background task until it finished, code below will help u:
NSDate *loopUntil = [NSDate dateWithTimeIntervalSinceNow:0.1];
while (![self isFinished] && [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:loopUntil]) {
loopUntil = [NSDate dateWithTimeIntervalSinceNow:0.1];
}
while (![self isFinished] && [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:loopUntil]) {
loopUntil = [NSDate dateWithTimeIntervalSinceNow:0.1];
}

