-
-
Notifications
You must be signed in to change notification settings - Fork 193
refactor(async): Modernize coroutine helpers and add follow_up functions #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for dpp-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
The existing coroutine helper functions in message_create_t and interaction_create_t used an unsafe [&] capture, which could lead to dangling references. This commit corrects the issue by capturing all parameters by value or move. Additionally, a new co_edit_original_response overload was added that accepts a const std::string& for consistency with other helper functions.
Mishura4
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point the right thing to do with these co_ functions would be to pass by value and then move in the lambda capture. With that said that'll require a lot of changes to the PHP script so, I think we should accept this PR for now, but if you want to have a shot at the PHP script to do that, feel free to
Refactors all async helper functions on message_create_t and interaction_create_t to use the pass-by-value idiom. This fixes a potential critical dangling reference bug across the async API. This change was enabled by making interaction_modal_response movable (Rule of Five).
|
The PR description has been updated. On a related note, I've noticed that this refactoring will make the Suggestions would be appreciated on this. |
Summary
This is a refactoring and stability improvement for the coroutine helper functions on
message_create_tandinteraction_create_t.Following a review discussion, all relevant
co_helpers have been updated to use the modern "pass-by-value and move" C++ idiom. This change achieves two primary goals:const&and&&overloads with a single, more efficient signature.To support this refactoring,
interaction_modal_responsewas also made fully copyable and movable by implementing the Rule of 5.This PR also introduces the
follow_upfunction as originally intended and includes several other minor improvements discovered during implementation.Changes
co_helpers (co_reply,co_send,co_edit_response, etc.) to take parameters by value. This corrects a systemic dangling reference bug and modernizes the API.interaction_modal_responseto make it a properly movable type, enabling its use with the new pass-by-value pattern.follow_upandco_follow_upfunctions tointeraction_create_t.co_edit_original_responseoverload that accepts astd::stringfor better consistency with similar functions.edit_original_responsenow usesconst&to avoid unnecessary copies of file data.Testing
All changes were thoroughly tested with a local bot, covering both lvalue (copy) and rvalue (move) call patterns for all refactored functions to ensure correctness and prevent regressions.
Code change checklist