mirror of
https://github.com/samsonjs/samhuri.net-ios.git
synced 2026-03-25 09:25:47 +00:00
20 lines
707 B
Objective-C
20 lines
707 B
Objective-C
#import <assert.h>
|
|
#import <Foundation/NSThread.h>
|
|
#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
|