Skip to content

Instantly share code, notes, and snippets.

@hSATAC
Forked from Phillipus/BlockMacros.h
Created January 15, 2014 05:19
Show Gist options
  • Save hSATAC/8431235 to your computer and use it in GitHub Desktop.
Save hSATAC/8431235 to your computer and use it in GitHub Desktop.
// Macro - Set the flag for block completion
#define StartBlock() __block BOOL waitingForBlock = YES
// Macro - Set the flag to stop the loop
#define EndBlock() waitingForBlock = NO
// Macro - Wait and loop until flag is set
#define WaitUntilBlockCompletes() WaitWhile(waitingForBlock)
// Macro - Wait for condition to be NO/false in blocks and asynchronous calls
// Each test should have its own instance of a BOOL condition because of non-thread safe operations
#define WaitWhile(condition) \
do { \
while(condition) { \
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \
} \
} while(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment