Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sentry/src/main/java/io/sentry/SentryWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,23 @@ public static <U> Supplier<U> wrapSupplier(final @NotNull Supplier<U> supplier)
}
};
}

/**
* Helper method to wrap {@link Runnable}
*
* <p>Forks current and isolation scope before execution and restores previous state afterwards.
* This prevents reused threads (e.g. from thread-pools) from getting an incorrect state.
*
* @param runnable - the {@link Runnable} to be wrapped
* @return the wrapped {@link Runnable}
*/
public static Runnable wrapRunnable(final @NotNull Runnable runnable) {
final IScopes newScopes = Sentry.forkedScopes("SentryWrapper.wrapRunnable");

return () -> {
try (ISentryLifecycleToken ignore = newScopes.makeCurrent()) {
runnable.run();
}
};
}
}
Loading