refactor: Use dispatch instead of post#7438
Open
bthomee wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors PeerImp’s strand scheduling to use boost::asio::dispatch in place of post + running_in_this_thread() checks, aligning more operations to consistently execute on the peer’s strand (following the direction from #7422).
Changes:
- Replaced multiple
post(strand_, ...)call sites withdispatch(strand_, ...)lambdas for peer lifecycle and message-handling entry points. - Centralized strand-hopping behavior by wrapping methods like
run,stop,send, and tx-queue helpers indispatch. - Removed
boost::asio/post.hppinclude and eliminated remainingpost(...)usage.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## bthomee/peer_charge #7438 +/- ##
===================================================
Coverage 82.3% 82.3%
===================================================
Files 1010 1010
Lines 76965 76956 -9
Branches 8984 8976 -8
===================================================
- Hits 63368 63367 -1
+ Misses 13588 13580 -8
Partials 9 9
🚀 New features to boost your workflow:
|
godexsoft
approved these changes
Jun 10, 2026
godexsoft
left a comment
Contributor
There was a problem hiding this comment.
Surprised captured self is not flagged by clang-tidy for places it is unused.. but it seems to work so all good 👍
| post(strand_, std::bind(&PeerImp::run, shared_from_this())); | ||
| return; | ||
| } | ||
| dispatch(strand_, [self = shared_from_this()]() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
High Level Overview of Change
This refactor changes the
postcalls todispatchcalls.Context of Change
This PR follows up on #7422. Dispatching the work to the strand makes the code a lot easier to read and maintain than posting the work.