Skip to content

Commit

Permalink
Use :tryfinally to avoid introducing scope in @with (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxl-th authored Jan 8, 2025
1 parent 58929e3 commit ed1d165
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ScopedValues"
uuid = "7e506255-f358-4e82-b7e4-beb19740aa63"
authors = ["Valentin Churavy <[email protected]>"]
version = "1.2.1"
version = "1.3.0"

[deps]
HashArrayMappedTries = "076d061b-32b6-4027-95e0-9a2c6f6d7e74"
Expand Down
14 changes: 8 additions & 6 deletions src/ScopedValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

2 comments on commit ed1d165

@vchuravy
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122642

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.0 -m "<description of version>" ed1d165f965efb235f08b27f38ea10576e765050
git push origin v1.3.0

Please sign in to comment.