iOS: remove sync in dealloc & add some weak-strong-dance
This commit is contained in:
parent
67915e6db0
commit
e0d76d218d
@ -87,24 +87,17 @@ - (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)unsubscribe:(NSString *)subscribeId withPromise:(DoricPromise *)promise {
|
- (void)unsubscribe:(NSString *)subscribeId withPromise:(DoricPromise *)promise {
|
||||||
__block id observer = nil;
|
|
||||||
dispatch_sync(self.syncQuene, ^{
|
|
||||||
observer = [self.observers objectForKey:subscribeId];
|
|
||||||
});
|
|
||||||
if (observer) {
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:observer];
|
|
||||||
dispatch_barrier_async(self.syncQuene, ^{
|
dispatch_barrier_async(self.syncQuene, ^{
|
||||||
|
id observer = [self.observers objectForKey:subscribeId];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:observer];
|
||||||
[self.observers removeObjectForKey:subscribeId];
|
[self.observers removeObjectForKey:subscribeId];
|
||||||
});
|
|
||||||
}
|
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
__block NSArray *values;
|
NSArray *values = [self.observers allValues];
|
||||||
dispatch_sync(self.syncQuene, ^{
|
|
||||||
values = [self.observers allValues];
|
|
||||||
});
|
|
||||||
[values enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
[values enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:obj];
|
[[NSNotificationCenter defaultCenter] removeObserver:obj];
|
||||||
}];
|
}];
|
||||||
|
Reference in New Issue
Block a user