@@ -24,26 +24,29 @@ public T get() {
2424 }
2525
2626 @ Override
27- public void with (T value , Runnable runnable ) {
28- ref .where (ref , value ).run (runnable );
27+ public <X extends Throwable > void with (T value , RunnableTx <X > runnable ) throws X {
28+ ref .where (ref , value ).call (() -> {
29+ runnable .run ();
30+ return null ;
31+ });
2932 }
3033
3134 @ Override
32- public <R > R with (T value , Supplier < R > callable ) {
33- return ref .where (ref , value ).call (callable ::get );
35+ public <R , X extends Throwable > R with (T value , CallableTx <? extends R , X > callable ) throws X {
36+ return ref .where (ref , value ).call (callable ::call );
3437 }
3538
3639 @ Override
37- public <X extends Throwable > void withOrThrow (T value , RunnableTx < X > runnable ) throws X {
40+ public <X extends Throwable > void with (T value , ConsumerTx < T , X > consumer ) throws X {
3841 ref .where (ref , value ).call (() -> {
39- runnable . run ( );
42+ consumer . accept ( ref . get () );
4043 return null ;
4144 });
4245 }
4346
4447 @ Override
45- public <R , X extends Throwable > R withOrThrow (T value , CallableTx < ? extends R , X > callable ) throws X {
46- return ref .where (ref , value ).call (callable :: call );
48+ public <R , X extends Throwable > R with (T value , FunctionTx < T , ? extends R , X > function ) throws X {
49+ return ref .where (ref , value ).call (() -> function . apply ( ref . get ()) );
4750 }
4851
4952 @ Override
@@ -56,4 +59,4 @@ public ScopeLocal<T> set(T value) {
5659 public void remove () {
5760 log .error ("ScopeLocal.remove is invalid, please use ScopeLocal.with" );
5861 }
59- }
62+ }
0 commit comments