Skip to main content

send_and_wait

Function send_and_wait 

Source
pub async fn send_and_wait<N, F, R>(
    node: &Node<N>,
    peer_id: &str,
    namespace: &str,
    msg_type: &str,
    payload: &Value,
    timeout: Duration,
    filter: F,
) -> Result<R, RequestError>
where N: NetworkProvider + 'static, F: Fn(&NamespacedMessage) -> Option<R>,
Expand description

Send a namespaced message and wait for a reply that matches a predicate.

  1. Subscribes to namespace (before sending, to avoid missing the reply).
  2. Sends the message via Node::send_typed.
  3. Loops on incoming messages, calling filter on each.
  4. Returns the first Some(R) from the filter, or times out.

The filter receives every message on the namespace, not just from the target peer — the caller decides what constitutes a valid reply.