Struct Notify

Source
pub struct Notify<const N: usize, T: Debug + Clone>(/* private fields */);
Expand description

Wait for notifications of new discoveries, buffering up to 256 discoveries, created using Chart::notify().

§Examples


   let mut node_discoverd = chart.notify();
   let maintain = discovery::maintain(chart.clone());
   let _ = tokio::spawn(maintain); // maintain task will run forever
    
   while chart.size() < full_size as usize {
       let new = node_discoverd.recv().await.unwrap();
       println!("discoverd new node: {:?}", new);
   }
}

Implementations§

Source§

impl<T: Debug + Clone> Notify<1, T>

Source

pub async fn recv_one(&mut self) -> Result<(Id, IpAddr, T), RecvError>

await the next discovered instance. Returns the id and custom messag for new node when it is discovered.

§Note

Can only be called on a Notify for a chart created with ChartBuilder::custom_msg()

§Errors

If more the 256 discoveries have been made since this was called this returns RecvError::Lagged

Source§

impl<const N: usize, T: Debug + Clone> Notify<N, T>

Source

pub async fn recv(&mut self) -> Result<(Id, IpAddr, [T; N]), RecvError>

await the next discovered instance. Returns the id and custom messages for new node when it is discovered.

§Note

Can only be called on a Notify for a chart created with ChartBuilder::custom_msg()

§Errors

If more the 256 discoveries have been made since this was called this returns RecvError::Lagged

Source

pub async fn recv_nth<const IDX: usize>( &mut self, ) -> Result<(Id, IpAddr, T), RecvError>

await the next discovered instance. Returns the id and nth custom messages for new node when it is discovered.

§Note

Can only be called on a Notify for a chart created with ChartBuilder::custom_msg()

§Errors

If more the 256 discoveries have been made since this was called this returns RecvError::Lagged

Source§

impl Notify<1, u16>

Source

pub async fn recv_addr(&mut self) -> Result<(Id, SocketAddr), RecvError>

await the next discovered instance. Returns the id and service adresses for new node when it is discovered.

§Note

Can only be called on a Notify for a chart created with ChartBuilder::finish() that had as single service port set.

§Errors

If more the 256 discoveries have been made since this was called this returns RecvError::Lagged

Source§

impl<const N: usize> Notify<N, u16>

Source

pub async fn recv_addresses( &mut self, ) -> Result<(Id, [SocketAddr; N]), RecvError>

await the next discovered instance. Buffers up to 256 discoveries. Returns the id and service adresseses for new node when it is discovered.

§Note

Can only be called on a Notify for a chart created with ChartBuilder::finish() that had multiple service ports set.

§Errors

If more the 256 discoveries have been made since this was called this returns RecvError::Lagged

Source

pub async fn recv_nth_addr<const IDX: usize>( &mut self, ) -> Result<(Id, SocketAddr), RecvError>

await the next discovered instance. Buffers up to 256 discoveries. Returns the id and nth service adresses for new node when it is discovered.

§Note

Can only be called on a Notify for a chart created with ChartBuilder::finish() that had multiple service ports set.

§Errors

If more the 256 discoveries have been made since this was called this returns RecvError::Lagged

Trait Implementations§

Source§

impl<const N: usize, T: Debug + Debug + Clone> Debug for Notify<N, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize, T> Freeze for Notify<N, T>

§

impl<const N: usize, T> RefUnwindSafe for Notify<N, T>

§

impl<const N: usize, T> Send for Notify<N, T>
where T: Send,

§

impl<const N: usize, T> Sync for Notify<N, T>
where T: Send,

§

impl<const N: usize, T> Unpin for Notify<N, T>

§

impl<const N: usize, T> UnwindSafe for Notify<N, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more