lnpeer: make process_message
async
#7835
Merged
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.
This allows making any message handler async in lnpeer.
Note:
process_message
is only called from_message_loop
.There are(would be) basically three types of message handlers:
process_message
naturally blocks until the handler returns, which means_message_loop
also blocks until the message is fully processed before starting the next iteration._message_loop
to wait until the handler finishes. We await the handler insideprocess_message
, and_message_loop
awaitsprocess_message
.Peer.taskgroup
and the loop is free to start processing subsequent messages. e.g. msg handlers that start a negotiation, such ason_shutdown
andon_open_channel
.Any non-async message handler (
def on_...
) automatically goes into category 1.An async message handler, by default, goes into category 2, "blocking";
to go into category 3 ("non-blocking"), we use the
runs_in_taskgroup
function decorator.