Skip to content

External Channel

An external channel wraps an external transport and provides a higher-level API for sending, receiving, and observing host-facing messages.

The external channel is available from the Context and can be used by components and other framework code.

See external::Channel for full API details.

Sending

Sending messages to the host is done by calling the send or try_send[1] method on the external channel:

rust
context.external_channel.send(message).await;

Receiving

Receiving messages from the host is done by creating a receiver instance by calling the receiver or try_receiver[1:1] method on the external channel, and then calling the next method on the receiver:

rust
let mut receiver = context.external_channel.receiver::<MyMessageType>()?;
let message = receiver.next().await;

Observing

Observing messages that will be sent to the host is done by creating an observer instance by calling the observer or try_observer[1:2] method on the external channel, and then calling the next method on the observer:

rust
let mut observer = context.external_channel.observer::<MyMessageType>()?;
let message = observer.next().await;


  1. The difference between the try_* methods and regular methods is that the try_* methods take any external message type, while the regular methods require that the message type is the one specified by the transport via the TxMessage/RxMessage associated types, or a type that can be converted to it via the TryFromMessage trait. The try_* methods can be used if you don't know the the message type of the external transport. If you do know the message type, the regular methods should be used, as they will check the message type at compile time and are a bit more performant. ↩︎ ↩︎ ↩︎