Skip to content

Commit 15fdf60

Browse files
committed
don’t await if there are no callbacks
1 parent 6780d71 commit 15fdf60

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/dart/lib/src/protocol/sentry_span.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ class SentrySpan extends ISentrySpan {
7878
}
7979

8080
// Dispatch OnSpanFinish lifecycle event
81-
await _hub.options.lifecycleRegistry.dispatchCallback(OnSpanFinish(this));
81+
final callback = _hub.options.lifecycleRegistry.dispatchCallback(OnSpanFinish(this));
82+
if (callback is Future) {
83+
await callback;
84+
}
8285

8386
// The finished flag depends on the _endTimestamp
8487
// If we set this earlier then finished is true and then we cannot use setData etc...

packages/dart/lib/src/sdk_lifecycle_hooks.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ class SdkLifecycleRegistry {
3434
callbacks?.remove(callback);
3535
}
3636

37-
FutureOr<void> dispatchCallback<T extends SdkLifecycleEvent>(T event) async {
37+
FutureOr<void> dispatchCallback<T extends SdkLifecycleEvent>(T event) {
38+
final callbacks = _lifecycleCallbacks[event.runtimeType];
39+
if (callbacks == null || callbacks.isEmpty) {
40+
// Return synchronously when there are no callbacks to avoid unnecessary async boundary
41+
return null;
42+
}
43+
return _dispatchCallbackAsync(event, callbacks);
44+
}
45+
46+
Future<void> _dispatchCallbackAsync<T extends SdkLifecycleEvent>(
47+
T event, List<Function> callbacks) async {
3848
final callbacks = _lifecycleCallbacks[event.runtimeType] ?? [];
3949
for (final cb in callbacks) {
4050
try {

0 commit comments

Comments
 (0)