Created
May 23, 2011 22:04
-
-
Save axiixc/987725 to your computer and use it in GitHub Desktop.
So fun story, notification observers are invoked on the thread from which you send the notification. Also I like GCD.
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
#import <dispatch/dispatch.h> | |
@interface NSNotificationCenter (Concurrency) | |
+ (void)onMainQueuePostNotificationName:(NSString *)notificationName object:(id)object; | |
+ (void)onMainQueuePostNotificationName:(NSString *)notificationName object:(id)object userInfo:(NSDictionary *)userInfo; | |
+ (void)onQueue:(dispatch_queue_t)queue postNotificationName:(NSString *)notificationName object:(id)object; | |
+ (void)onQueue:(dispatch_queue_t)queue postNotificationName:(NSString *)notificationName object:(id)object userInfo:(NSDictionary *)userInfo; | |
@end |
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
#import "NSNotificationCenter+Concurrency.h" | |
@implementation NSNotificationCenter (Concurrency) | |
+ (void)onMainQueuePostNotificationName:(NSString *)notificationName object:(id)object | |
{ | |
[self onQueue:dispatch_get_main_queue() postNotificationName:notificationName object:object]; | |
} | |
+ (void)onMainQueuePostNotificationName:(NSString *)notificationName object:(id)object userInfo:(NSDictionary *)userInfo | |
{ | |
[self onQueue:dispatch_get_main_queue() postNotificationName:notificationName object:object userInfo:userInfo]; | |
} | |
+ (void)onQueue:(dispatch_queue_t)queue postNotificationName:(NSString *)notificationName object:(id)object | |
{ | |
dispatch_async(queue, ^{ | |
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:object]; | |
}); | |
} | |
+ (void)onQueue:(dispatch_queue_t)queue postNotificationName:(NSString *)notificationName object:(id)object userInfo:(NSDictionary *)userInfo | |
{ | |
dispatch_async(queue, ^{ | |
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:object userInfo:userInfo]; | |
}); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment