samhuri.net-ios/Pods/PromiseKit/objc/NSNotificationCenter+PromiseKit.m
2014-10-18 14:19:51 -07:00

18 lines
656 B
Objective-C

#import "NSNotificationCenter+PromiseKit.h"
#import "PromiseKit/Promise.h"
@implementation NSNotificationCenter (PromiseKit)
+ (PMKPromise *)once:(NSString *)name {
return [PMKPromise new:^(PMKPromiseFulfiller fulfiller, PMKPromiseRejecter rejecter) {
__block id identifier = [[NSNotificationCenter defaultCenter] addObserverForName:name object:nil queue:PMKOperationQueue() usingBlock:^(NSNotification *note) {
assert(!NSThread.isMainThread);
[[NSNotificationCenter defaultCenter] removeObserver:identifier name:name object:nil];
fulfiller(PMKManifold(note, note.userInfo));
}];
}];
}
@end