diff --git a/Project.toml b/Project.toml index e208f71..1c00b7e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ScopedValues" uuid = "7e506255-f358-4e82-b7e4-beb19740aa63" authors = ["Valentin Churavy "] -version = "1.2.1" +version = "1.3.0" [deps] HashArrayMappedTries = "076d061b-32b6-4027-95e0-9a2c6f6d7e74" diff --git a/src/ScopedValues.jl b/src/ScopedValues.jl index 6cb326a..a70b800 100644 --- a/src/ScopedValues.jl +++ b/src/ScopedValues.jl @@ -200,17 +200,19 @@ macro with(exprs...) end end +macro __tryfinally(ex, fin) + Expr(:tryfinally, + :($(esc(ex))), + :($(esc(fin))), + ) +end + # Macro version of `Base.CoreLogging.with_logstate` macro with_logstate(logstate, expr) quote t = $current_task() old = t.logstate - try - t.logstate = logstate - $(esc(expr)) - finally - t.logstate = old - end + @__tryfinally (t.logstate = logstate; $(esc(expr))) (t.logstate = old;) end end