Skip to content

Commit b39770b

Browse files
swarm/src/behaviour: Document impact of blocking code (#2482)
Co-authored-by: Max Inden <[email protected]>
1 parent 44d63d8 commit b39770b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

swarm/src/behaviour.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ type THandlerInEvent<THandler> =
152152
/// struct members are delegated to [`NetworkBehaviourEventProcess`] implementations. Those must be
153153
/// provided by the user on the type that [`NetworkBehaviour`] is derived on.
154154
///
155+
/// Because these implementations are granted exclusive access to the [`NetworkBehaviour`],
156+
/// [blocking code](https://ryhl.io/blog/async-what-is-blocking/) in these implementations will
157+
/// block the entire [`Swarm`](crate::Swarm) from processing new events, since the swarm cannot progress
158+
/// without also having exclusive access to the [`NetworkBehaviour`]. A better alternative is to execute
159+
/// blocking or asynchronous logic on a separate task, perhaps with the help of a bounded channel to
160+
/// maintain backpressure. The sender for the channel could be included in the NetworkBehaviours constructor.
161+
///
155162
/// Optionally one can provide a custom `poll` function through the `#[behaviour(poll_method =
156163
/// "poll")]` attribute. This function must have the same signature as the [`NetworkBehaviour#poll`]
157164
/// function and will be called last within the generated [`NetworkBehaviour`] implementation.

0 commit comments

Comments
 (0)