Skip to content

Add on_setup_once and on_teardown_once convenience methods#209

Merged
ryanoneill merged 1 commit intomainfrom
feature/hook-once-methods
Mar 9, 2026
Merged

Add on_setup_once and on_teardown_once convenience methods#209
ryanoneill merged 1 commit intomainfrom
feature/hook-once-methods

Conversation

@ryanoneill
Copy link
Owner

Summary

  • Adds on_setup_once and on_teardown_once methods to RuntimeConfig that accept FnOnce closures, eliminating the need for Arc<Mutex<Option<...>>> wrappers when hooks consume captured state
  • Wraps FnOnce internally with a Mutex to maintain compatibility with the existing Fn-based TerminalHook type and RuntimeConfig: Clone
  • Adds 7 tests covering storage, callability, run-once semantics, consuming captures, and clone behavior

Test plan

  • All 7 new tests pass (cargo test --all-features --lib -- config::tests)
  • Full test suite passes (4088 tests)
  • cargo clippy --all-features -- -D warnings clean
  • CI passes

🤖 Generated with Claude Code

@codecov-commenter
Copy link

codecov-commenter commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.08%. Comparing base (3bddb37) to head (e545825).

Files with missing lines Patch % Lines
src/app/runtime/config.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #209      +/-   ##
==========================================
- Coverage   92.08%   92.08%   -0.01%     
==========================================
  Files         144      144              
  Lines       12766    12778      +12     
==========================================
+ Hits        11756    11767      +11     
- Misses       1010     1011       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ryanoneill ryanoneill force-pushed the feature/hook-once-methods branch 2 times, most recently from 0839449 to af3d7e5 Compare March 9, 2026 00:58
…Config

The existing hook API requires `Fn` closures, which forces users into
interior mutability patterns when they need to consume captured values.
Since hooks run at most once, `FnOnce` is semantically correct. These
new methods accept `FnOnce` closures and wrap them internally with a
Mutex to maintain compatibility with the `Fn`-based `TerminalHook` type
and `RuntimeConfig: Clone`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ryanoneill ryanoneill force-pushed the feature/hook-once-methods branch from af3d7e5 to e545825 Compare March 9, 2026 01:10
@ryanoneill ryanoneill merged commit 18a5375 into main Mar 9, 2026
17 checks passed
ryanoneill added a commit that referenced this pull request Mar 9, 2026
Replace on_setup(Arc::new(|| ...)) with on_setup_once(|| ...) to
demonstrate the preferred FnOnce convenience API added in PR #209.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants