Skip to content

Commit 68db6a8

Browse files
committed
优化 solon-java25 的 ScopeLocal 适配
1 parent ed490dd commit 68db6a8

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

UPDATE_LOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
### v3.8.1
3+
4+
* 优化 `solon-java25` 的 ScopeLocal 适配

src/main/java/org/noear/solon/util/ScopeLocalJdk25.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)