mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
NSRunLoop methods should only be accessed on it's corresponding thread.
This commit is contained in:
parent
64cdaae02e
commit
323249baa0
3 changed files with 17 additions and 43 deletions
|
@ -14,12 +14,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
userInfo:(nullable id)userInfo
|
userInfo:(nullable id)userInfo
|
||||||
repeats:(BOOL)repeats;
|
repeats:(BOOL)repeats;
|
||||||
|
|
||||||
+ (NSTimer *)weakTimerWithTimeInterval:(NSTimeInterval)timeInterval
|
|
||||||
target:(id)target
|
|
||||||
selector:(SEL)selector
|
|
||||||
userInfo:(nullable id)userInfo
|
|
||||||
repeats:(BOOL)repeats;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -64,24 +64,6 @@ static void *kNSTimer_OWS_Proxy = &kNSTimer_OWS_Proxy;
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSTimer *)weakTimerWithTimeInterval:(NSTimeInterval)timeInterval
|
|
||||||
target:(id)target
|
|
||||||
selector:(SEL)selector
|
|
||||||
userInfo:(nullable id)userInfo
|
|
||||||
repeats:(BOOL)repeats
|
|
||||||
{
|
|
||||||
NSTimerProxy *proxy = [NSTimerProxy new];
|
|
||||||
proxy.target = target;
|
|
||||||
proxy.selector = selector;
|
|
||||||
NSTimer *timer = [NSTimer timerWithTimeInterval:timeInterval
|
|
||||||
target:proxy
|
|
||||||
selector:@selector(timerFired:)
|
|
||||||
userInfo:userInfo
|
|
||||||
repeats:repeats];
|
|
||||||
[timer ows_setProxy:proxy];
|
|
||||||
return timer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -192,25 +192,23 @@ NSString *const OWSOperationKeyIsFinished = @"isFinished";
|
||||||
|
|
||||||
self.remainingRetries--;
|
self.remainingRetries--;
|
||||||
|
|
||||||
dispatch_sync(self.retryTimerSerialQueue, ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
OWSAssertDebug(self.retryTimer == nil);
|
dispatch_sync(self.retryTimerSerialQueue, ^{
|
||||||
[self.retryTimer invalidate];
|
OWSAssertDebug(self.retryTimer == nil);
|
||||||
NSTimer *retryTimer = [NSTimer weakTimerWithTimeInterval:self.retryInterval
|
[self.retryTimer invalidate];
|
||||||
target:self
|
// The `scheduledTimerWith*` methods add the timer to the current thread's RunLoop.
|
||||||
selector:@selector(runAnyQueuedRetry)
|
// Since Operations typically run on a background thread, that would mean the background
|
||||||
userInfo:nil
|
// thread's RunLoop. However, the OS can spin down background threads if there's no work
|
||||||
repeats:NO];
|
// being done, so we run the risk of the timer's RunLoop being deallocated before it's
|
||||||
|
// fired.
|
||||||
self.retryTimer = retryTimer;
|
//
|
||||||
|
// To ensure the timer's thread sticks around, we schedule it while on the main RunLoop.
|
||||||
// The `scheduledTimerWith*` methods add the timer to the current thread's RunLoop.
|
self.retryTimer = [NSTimer weakScheduledTimerWithTimeInterval:self.retryInterval
|
||||||
// Since Operations typically run on a background thread, that would mean the background
|
target:self
|
||||||
// thread's RunLoop. However, the OS can spin down background threads if there's no work
|
selector:@selector(runAnyQueuedRetry)
|
||||||
// being done, so we run the risk of the timer's RunLoop being deallocated before it's
|
userInfo:nil
|
||||||
// fired.
|
repeats:NO];
|
||||||
//
|
});
|
||||||
// To ensure the timer's thread sticks around, we schedule it on the main RunLoop.
|
|
||||||
[NSRunLoop.mainRunLoop addTimer:retryTimer forMode:NSDefaultRunLoopMode];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue