File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
sentry/src/main/java/io/sentry Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -57,4 +57,23 @@ public static <U> Supplier<U> wrapSupplier(final @NotNull Supplier<U> supplier)
5757 }
5858 };
5959 }
60+
61+ /**
62+ * Helper method to wrap {@link Runnable}
63+ *
64+ * <p>Forks current and isolation scope before execution and restores previous state afterwards.
65+ * This prevents reused threads (e.g. from thread-pools) from getting an incorrect state.
66+ *
67+ * @param runnable - the {@link Runnable} to be wrapped
68+ * @return the wrapped {@link Runnable}
69+ */
70+ public static Runnable wrapRunnable (final @ NotNull Runnable runnable ) {
71+ final IScopes newScopes = Sentry .forkedScopes ("SentryWrapper.wrapRunnable" );
72+
73+ return () -> {
74+ try (ISentryLifecycleToken ignore = newScopes .makeCurrent ()) {
75+ runnable .run ();
76+ }
77+ };
78+ }
6079}
You can’t perform that action at this time.
0 commit comments