@@ -40,14 +40,12 @@ use super::{
40
40
/// A [`LivelinessToken`](LivelinessToken) is a token which liveliness is tied
41
41
/// to the Zenoh [`Session`](Session) and can be monitored by remote applications.
42
42
///
43
- /// A [`LivelinessToken`](LivelinessToken) with key `key/expression` can be
44
- /// queried or subscribed to on key `@/liveliness/key/expression`.
45
- ///
46
43
/// The `Liveliness` structure can be obtained with the
47
44
/// [`Session::liveliness()`](Session::liveliness) function
48
45
/// of the [`Session`] struct.
49
46
///
50
47
/// # Examples
48
+ /// ### Declaring a token
51
49
/// ```
52
50
/// # #[tokio::main]
53
51
/// # async fn main() {
@@ -61,6 +59,39 @@ use super::{
61
59
/// .unwrap();
62
60
/// # }
63
61
/// ```
62
+ ///
63
+ /// ### Querying tokens
64
+ /// ```
65
+ /// # #[tokio::main]
66
+ /// # async fn main() {
67
+ /// use zenoh::prelude::*;
68
+ ///
69
+ /// let session = zenoh::open(zenoh::config::peer()).await.unwrap();
70
+ /// let replies = session.liveliness().get("key/**").await.unwrap();
71
+ /// while let Ok(reply) = replies.recv_async().await {
72
+ /// if let Ok(sample) = reply.result() {
73
+ /// println!(">> Liveliness token {}", sample.key_expr());
74
+ /// }
75
+ /// }
76
+ /// # }
77
+ /// ```
78
+ ///
79
+ /// ### Subscribing to liveliness changes
80
+ /// ```no_run
81
+ /// # #[tokio::main]
82
+ /// # async fn main() {
83
+ /// use zenoh::{prelude::*, sample::SampleKind};
84
+ ///
85
+ /// let session = zenoh::open(zenoh::config::peer()).await.unwrap();
86
+ /// let subscriber = session.liveliness().declare_subscriber("key/**").await.unwrap();
87
+ /// while let Ok(sample) = subscriber.recv_async().await {
88
+ /// match sample.kind() {
89
+ /// SampleKind::Put => println!("New liveliness: {}", sample.key_expr()),
90
+ /// SampleKind::Delete => println!("Lost liveliness: {}", sample.key_expr()),
91
+ /// }
92
+ /// }
93
+ /// # }
94
+ /// ```
64
95
#[ zenoh_macros:: unstable]
65
96
pub struct Liveliness < ' a > {
66
97
pub ( crate ) session : SessionRef < ' a > ,
@@ -250,9 +281,6 @@ pub(crate) struct LivelinessTokenState {
250
281
/// A token whose liveliness is tied to the Zenoh [`Session`](Session)
251
282
/// and can be monitored by remote applications.
252
283
///
253
- /// A `LivelinessToken` with key `key/expression` can be queried or subscribed
254
- /// to on key `@/liveliness/key/expression`.
255
- ///
256
284
/// A declared liveliness token will be seen as alive by any other Zenoh
257
285
/// application in the system that monitors it while the liveliness token
258
286
/// is not undeclared or dropped, while the Zenoh application that declared
@@ -388,7 +416,7 @@ impl Drop for LivelinessToken<'_> {
388
416
}
389
417
}
390
418
391
- /// A builder for initializing a [`FlumeSubscriber`](FlumeSubscriber).
419
+ /// A builder for initializing a liveliness [`FlumeSubscriber`](FlumeSubscriber).
392
420
///
393
421
/// # Examples
394
422
/// ```
@@ -398,8 +426,8 @@ impl Drop for LivelinessToken<'_> {
398
426
///
399
427
/// let session = zenoh::open(zenoh::config::peer()).await.unwrap();
400
428
/// let subscriber = session
429
+ /// .liveliness()
401
430
/// .declare_subscriber("key/expression")
402
- /// .best_effort()
403
431
/// .await
404
432
/// .unwrap();
405
433
/// # }
@@ -415,7 +443,7 @@ pub struct LivelinessSubscriberBuilder<'a, 'b, Handler> {
415
443
416
444
#[ zenoh_macros:: unstable]
417
445
impl < ' a , ' b > LivelinessSubscriberBuilder < ' a , ' b , DefaultHandler > {
418
- /// Receive the samples for this subscription with a callback.
446
+ /// Receive the samples for this liveliness subscription with a callback.
419
447
///
420
448
/// # Examples
421
449
/// ```
@@ -425,6 +453,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
425
453
///
426
454
/// let session = zenoh::open(zenoh::config::peer()).await.unwrap();
427
455
/// let subscriber = session
456
+ /// .liveliness()
428
457
/// .declare_subscriber("key/expression")
429
458
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr(), sample.payload()); })
430
459
/// .await
@@ -452,10 +481,10 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
452
481
}
453
482
}
454
483
455
- /// Receive the samples for this subscription with a mutable callback.
484
+ /// Receive the samples for this liveliness subscription with a mutable callback.
456
485
///
457
486
/// Using this guarantees that your callback will never be called concurrently.
458
- /// If your callback is also accepted by the [`callback`](SubscriberBuilder ::callback) method, we suggest you use it instead of `callback_mut`
487
+ /// If your callback is also accepted by the [`callback`](LivelinessSubscriberBuilder ::callback) method, we suggest you use it instead of `callback_mut`
459
488
///
460
489
/// # Examples
461
490
/// ```
@@ -466,6 +495,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
466
495
/// let session = zenoh::open(zenoh::config::peer()).await.unwrap();
467
496
/// let mut n = 0;
468
497
/// let subscriber = session
498
+ /// .liveliness()
469
499
/// .declare_subscriber("key/expression")
470
500
/// .callback_mut(move |_sample| { n += 1; })
471
501
/// .await
@@ -484,7 +514,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
484
514
self . callback ( locked ( callback) )
485
515
}
486
516
487
- /// Receive the samples for this subscription with a [`Handler`](crate::prelude::IntoHandler).
517
+ /// Receive the samples for this liveliness subscription with a [`Handler`](crate::prelude::IntoHandler).
488
518
///
489
519
/// # Examples
490
520
/// ```no_run
@@ -494,6 +524,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
494
524
///
495
525
/// let session = zenoh::open(zenoh::config::peer()).await.unwrap();
496
526
/// let subscriber = session
527
+ /// .liveliness()
497
528
/// .declare_subscriber("key/expression")
498
529
/// .with(flume::bounded(32))
499
530
/// .await
@@ -642,7 +673,7 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> {
642
673
}
643
674
}
644
675
645
- /// Receive the replies for this query with a mutable callback.
676
+ /// Receive the replies for this liveliness query with a mutable callback.
646
677
///
647
678
/// Using this guarantees that your callback will never be called concurrently.
648
679
/// If your callback is also accepted by the [`callback`](LivelinessGetBuilder::callback) method, we suggest you use it instead of `callback_mut`
@@ -674,7 +705,7 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> {
674
705
self . callback ( locked ( callback) )
675
706
}
676
707
677
- /// Receive the replies for this query with a [`Handler`](crate::prelude::IntoHandler).
708
+ /// Receive the replies for this liveliness query with a [`Handler`](crate::prelude::IntoHandler).
678
709
///
679
710
/// # Examples
680
711
/// ```
0 commit comments