Skip to content

Commit

Permalink
ref: Add DispatchQueue property (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphofmann committed Dec 18, 2023
1 parent d78ee13 commit f38656b
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,6 +129,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti
}

_configuration = configuration;
_dispatchQueue = SentryDependencyContainer.sharedInstance.dispatchQueueWrapper;

self.transactionContext = transactionContext;
_children = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -195,36 +197,31 @@ - (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. "
@"Finishing transaction");
// 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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f38656b

Please sign in to comment.