Permalink
Browse files

-[NSThread ks_performBlockAndWait:]

  • Loading branch information...
1 parent e8bc9a6 commit 39fd403b4406e4793a0b88ce438fca448032524d @mikeabdullah mikeabdullah committed Jan 22, 2012
Showing with 30 additions and 0 deletions.
  1. +11 −0 KSThreadProxy.h
  2. +19 −0 KSThreadProxy.m
View
@@ -49,3 +49,14 @@
// Just for fun, a macro that gives you a proxy to NSWorkspace on the main thread
#define KSWORKSPACETHREADPROXY [[[NSWorkspace ks_proxyOnThread:nil] sharedWorkspace] ks_proxyOnThread:nil]
+
+
+#ifdef NS_BLOCKS_AVAILABLE
+@interface NSThread (KSThreadProxy)
+
+// Like dispatch_sync, but copes with the current thread being the same as the one targeted
+// Think of it is as a modern equivelant to -performSelector:onThread:withObject:waitUntilDone:
+- (void)ks_performBlockAndWait:(void (^)())block;
+
+@end
+#endif
View
@@ -144,3 +144,22 @@ - (id)ks_proxyOnThread:(NSThread *)thread waitUntilDone:(BOOL)waitUntilDone;
@end
+#pragma mark -
+
+
+#ifdef NS_BLOCKS_AVAILABLE
+@implementation NSThread (KSThreadProxy)
+
+- (void)ks_executeBlock:(void (^)())block;
+{
+ block();
+}
+
+- (void)ks_performBlockAndWait:(void (^)())block;
+{
+ [self performSelector:@selector(ks_executeBlock:) onThread:self withObject:block waitUntilDone:YES];
+}
+
+@end
+#endif
+

0 comments on commit 39fd403

Please sign in to comment.