Struct instance_chart::Notify

source ·
pub struct Notify<const N: usize, T: Debug + Clone>(_);
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> !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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

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