Created
March 19, 2012 06:18
-
-
Save swillits/2098574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void __AllowOnceEvery(double seconds, void (^block)(void), NSTimeInterval * lastTime) | |
{ | |
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; | |
if (now - *lastTime > seconds) { | |
*lastTime = now; | |
block(); | |
} | |
} | |
#define AllowOnceEvery(seconds, block) \ | |
do {\ | |
static NSTimeInterval lastTime = 0;\ | |
__AllowOnceEvery(seconds, block, &lastTime);\ | |
} while (0) | |
int main (int argc, const char * argv[]) | |
{ | |
BOOL done = NO; | |
// Do some long process | |
do { | |
@autoreleasepool { | |
// Do some work | |
done = work(); | |
// Send progress updates | |
AllowOnceEvery(1.0, ^{ | |
printf("Progress: %f", progress); | |
}); | |
} | |
} while (!done); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment