feat(iroh)!: make ProtocolHandler use async functions #3320
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.
Description
This changes the
ProtocolHandler
trait so that the functions returnimpl Future
instead ofBoxFuture
, which means implementors can simply implement the trait withasync fn
. We don't even need a'static
bound on these futures, so you can use&self
freely without cloning and moving.Internally, we still box the futures return by
accept
,on_connecting
andshutdown
. So performance wise this change should not have any effects. But the boxing is hidden from the user and implementing the trait now feels a lot more normal and simpler.Breaking Changes
iroh::protocol::ProtocolHandler
methods now returnimpl Future
instead ofBoxFuture
. You can simply remove theBox::pin(async move {})
from the implementations and instead implement the methods asasync fn
. See the updated documentation for theiroh::protocol
module for an example.iroh::protocol::ProtocolHandler
is no longer dyn-compatible. If you need a dyn-compatible version, you need to build your own dyn-compatible wrapper trait. See the (non-public)DynProtocolHandler
iniroh::protocol
as an example.Notes & open questions
Change checklist
quic-rpc
iroh-gossip
iroh-blobs
dumbpipe
sendme