diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 145ccf15fb3..cd15bdefb7e 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -70,6 +70,7 @@ @property (nonatomic) BOOL wasFinishCalled; @property (nonatomic, nullable, strong) NSTimer *deadlineTimer; @property (nonnull, strong) SentryTracerConfiguration *configuration; +@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueue; #if SENTRY_TARGET_PROFILING_SUPPORTED @property (nonatomic) BOOL isProfiling; @@ -128,6 +129,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti } _configuration = configuration; + _dispatchQueue = SentryDependencyContainer.sharedInstance.dispatchQueueWrapper; self.transactionContext = transactionContext; _children = [[NSMutableArray alloc] init]; @@ -195,18 +197,16 @@ - (void)dispatchIdleTimeout { @synchronized(_idleTimeoutLock) { if (_idleTimeoutBlock != NULL) { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper - dispatchCancel:_idleTimeoutBlock]; + [_dispatchQueue dispatchCancel:_idleTimeoutBlock]; } __weak SentryTracer *weakSelf = self; - _idleTimeoutBlock = - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper createDispatchBlock:^{ - if (weakSelf == nil) { - SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not doing anything."); - return; - } - [weakSelf finishInternal]; - }]; + _idleTimeoutBlock = [_dispatchQueue createDispatchBlock:^{ + if (weakSelf == nil) { + SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not doing anything."); + return; + } + [weakSelf finishInternal]; + }]; if (_idleTimeoutBlock == NULL) { SENTRY_LOG_WARN(@"Couldn't create idle time out block. Can't schedule idle timeout. " @@ -214,17 +214,14 @@ - (void)dispatchIdleTimeout // If the transaction has no children, the SDK will discard it. [self finishInternal]; } else { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper - dispatchAfter:_configuration.idleTimeout - block:_idleTimeoutBlock]; + [_dispatchQueue dispatchAfter:_configuration.idleTimeout block:_idleTimeoutBlock]; } } } - (BOOL)hasIdleTimeout { - return _configuration.idleTimeout > 0 - && SentryDependencyContainer.sharedInstance.dispatchQueueWrapper != nil; + return _configuration.idleTimeout > 0; } - (BOOL)isAutoGeneratedTransaction @@ -245,7 +242,7 @@ - (void)cancelIdleTimeout - (void)startDeadlineTimer { __weak SentryTracer *weakSelf = self; - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchOnMainQueue:^{ + [_dispatchQueue dispatchOnMainQueue:^{ weakSelf.deadlineTimer = [weakSelf.configuration.timerFactory scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE repeats:NO @@ -287,7 +284,7 @@ - (void)cancelDeadlineTimer // The timer must be invalidated from the thread on which the timer was installed, see // https://developer.apple.com/documentation/foundation/nstimer/1415405-invalidate#1770468 - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchOnMainQueue:^{ + [_dispatchQueue dispatchOnMainQueue:^{ if (weakSelf == nil) { SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not invalidating deadlineTimer."); return;