diff --git a/ci/valgrind-check/src/pub_sub/bin/z_pub_sub.rs b/ci/valgrind-check/src/pub_sub/bin/z_pub_sub.rs index a6ee4c9883..963177fcde 100644 --- a/ci/valgrind-check/src/pub_sub/bin/z_pub_sub.rs +++ b/ci/valgrind-check/src/pub_sub/bin/z_pub_sub.rs @@ -26,15 +26,11 @@ async fn main() { let sub_key_expr = KeyExpr::try_from("test/valgrind/**").unwrap(); println!("Declaring Publisher on '{pub_key_expr}'..."); - let pub_session = zenoh::open(Config::default()).res().await.unwrap(); - let publisher = pub_session - .declare_publisher(&pub_key_expr) - .res() - .await - .unwrap(); + let pub_session = zenoh::open(Config::default()).await.unwrap(); + let publisher = pub_session.declare_publisher(&pub_key_expr).await.unwrap(); println!("Declaring Subscriber on '{sub_key_expr}'..."); - let sub_session = zenoh::open(Config::default()).res().await.unwrap(); + let sub_session = zenoh::open(Config::default()).await.unwrap(); let _subscriber = sub_session .declare_subscriber(&sub_key_expr) .callback(|sample| { @@ -48,7 +44,6 @@ async fn main() { .unwrap_or_else(|e| format!("{}", e)) ); }) - .res() .await .unwrap(); @@ -56,7 +51,7 @@ async fn main() { tokio::time::sleep(Duration::from_secs(1)).await; let buf = format!("[{idx:4}] data"); println!("Putting Data ('{}': '{}')...", &pub_key_expr, buf); - publisher.put(buf).res().await.unwrap(); + publisher.put(buf).await.unwrap(); } tokio::time::sleep(Duration::from_secs(1)).await; diff --git a/ci/valgrind-check/src/queryable_get/bin/z_queryable_get.rs b/ci/valgrind-check/src/queryable_get/bin/z_queryable_get.rs index 08233039b8..6a94f14372 100644 --- a/ci/valgrind-check/src/queryable_get/bin/z_queryable_get.rs +++ b/ci/valgrind-check/src/queryable_get/bin/z_queryable_get.rs @@ -27,7 +27,7 @@ async fn main() { let get_selector = Selector::try_from("test/valgrind/**").unwrap(); println!("Declaring Queryable on '{queryable_key_expr}'..."); - let queryable_session = zenoh::open(Config::default()).res().await.unwrap(); + let queryable_session = zenoh::open(Config::default()).await.unwrap(); let _queryable = queryable_session .declare_queryable(&queryable_key_expr.clone()) .callback(move |query| { @@ -38,18 +38,16 @@ async fn main() { query.selector().key_expr(), query.value().unwrap().payload().clone(), ) - .res() .await .unwrap(); }); }) .complete(true) - .res() .await .unwrap(); println!("Declaring Get session for '{get_selector}'..."); - let get_session = zenoh::open(Config::default()).res().await.unwrap(); + let get_session = zenoh::open(Config::default()).await.unwrap(); for idx in 0..5 { tokio::time::sleep(Duration::from_secs(1)).await; @@ -58,7 +56,6 @@ async fn main() { .get(&get_selector) .value(idx) .target(QueryTarget::All) - .res() .await .unwrap(); while let Ok(reply) = replies.recv_async().await { diff --git a/commons/zenoh-core/src/lib.rs b/commons/zenoh-core/src/lib.rs index e15ff1d3bf..bdd2f9adaf 100644 --- a/commons/zenoh-core/src/lib.rs +++ b/commons/zenoh-core/src/lib.rs @@ -20,7 +20,7 @@ pub use lazy_static::lazy_static; pub mod macros; -use std::future::{Future, Ready}; +use std::future::{Future, IntoFuture, Ready}; // Re-exports after moving ZError/ZResult to zenoh-result pub use zenoh_result::{bail, to_zerror, zerror}; @@ -36,15 +36,14 @@ pub trait Resolvable { pub trait AsyncResolve: Resolvable { type Future: Future::To> + Send; +} - fn res_async(self) -> Self::Future; - - fn res(self) -> Self::Future - where - Self: Sized, - { - self.res_async() - } +impl AsyncResolve for T +where + T: Resolvable + IntoFuture, + T::IntoFuture: Send, +{ + type Future = T::IntoFuture; } pub trait SyncResolve: Resolvable { @@ -62,14 +61,25 @@ pub trait SyncResolve: Resolvable { /// /// Builder patterns in Zenoh can be resolved with [`AsyncResolve`] in async context and [`SyncResolve`] in sync context. /// In both async and sync context calling `.res()` resolves the builder. -/// `.res()` maps to `.res_async()` in async context. +/// `.res()` maps to `` in async context. /// `.res()` maps to `.res_sync()` in sync context. /// We advise to prefer the usage of [`AsyncResolve`] and to use [`SyncResolve`] with caution. #[must_use = "Resolvables do nothing unless you resolve them using `.res()`."] -pub trait Resolve: Resolvable + SyncResolve + AsyncResolve + Send {} +pub trait Resolve: + Resolvable + + SyncResolve + + AsyncResolve + + IntoFuture::Future, Output = Output> + + Send +{ +} impl Resolve for T where - T: Resolvable + SyncResolve + AsyncResolve + Send + T: Resolvable + + SyncResolve + + AsyncResolve + + IntoFuture::Future, Output = Output> + + Send { } @@ -98,14 +108,15 @@ where type To = To; } -impl AsyncResolve for ResolveClosure +impl IntoFuture for ResolveClosure where To: Sized + Send, C: FnOnce() -> To + Send, { - type Future = Ready<::To>; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -145,14 +156,15 @@ where type To = To; } -impl AsyncResolve for ResolveFuture +impl IntoFuture for ResolveFuture where To: Sized + Send, F: Future + Send, { - type Future = F; + type Output = To; + type IntoFuture = F; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { self.0 } } diff --git a/commons/zenoh-core/src/macros.rs b/commons/zenoh-core/src/macros.rs index d8f2f1fdc3..f20f22f41a 100644 --- a/commons/zenoh-core/src/macros.rs +++ b/commons/zenoh-core/src/macros.rs @@ -233,6 +233,8 @@ macro_rules! zcondfeat { #[macro_export] macro_rules! ztimeout { ($f:expr) => { - tokio::time::timeout(TIMEOUT, $f).await.unwrap() + tokio::time::timeout(TIMEOUT, ::core::future::IntoFuture::into_future($f)) + .await + .unwrap() }; } diff --git a/examples/examples/z_delete.rs b/examples/examples/z_delete.rs index ad87227fcd..6bd815dc5e 100644 --- a/examples/examples/z_delete.rs +++ b/examples/examples/z_delete.rs @@ -24,12 +24,12 @@ async fn main() { let (config, key_expr) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Deleting resources matching '{key_expr}'..."); - session.delete(&key_expr).res().await.unwrap(); + session.delete(&key_expr).await.unwrap(); - session.close().res().await.unwrap(); + session.close().await.unwrap(); } #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] diff --git a/examples/examples/z_forward.rs b/examples/examples/z_forward.rs index 9541511e84..3f33519af1 100644 --- a/examples/examples/z_forward.rs +++ b/examples/examples/z_forward.rs @@ -25,12 +25,12 @@ async fn main() { let (config, key_expr, forward) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Subscriber on '{key_expr}'..."); - let mut subscriber = session.declare_subscriber(&key_expr).res().await.unwrap(); + let mut subscriber = session.declare_subscriber(&key_expr).await.unwrap(); println!("Declaring Publisher on '{forward}'..."); - let publisher = session.declare_publisher(&forward).res().await.unwrap(); + let publisher = session.declare_publisher(&forward).await.unwrap(); println!("Forwarding data from '{key_expr}' to '{forward}'..."); subscriber.forward(publisher).await.unwrap(); } diff --git a/examples/examples/z_get.rs b/examples/examples/z_get.rs index 19122c9bcd..f6f99621e4 100644 --- a/examples/examples/z_get.rs +++ b/examples/examples/z_get.rs @@ -25,7 +25,7 @@ async fn main() { let (config, selector, value, target, timeout) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Sending Query '{selector}'..."); let replies = session @@ -37,7 +37,6 @@ async fn main() { .value(value) .target(target) .timeout(timeout) - .res() .await .unwrap(); while let Ok(reply) = replies.recv_async().await { diff --git a/examples/examples/z_get_liveliness.rs b/examples/examples/z_get_liveliness.rs index add38e967f..aa4c2f4bc1 100644 --- a/examples/examples/z_get_liveliness.rs +++ b/examples/examples/z_get_liveliness.rs @@ -25,14 +25,13 @@ async fn main() { let (config, key_expr, timeout) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Sending Liveliness Query '{key_expr}'..."); let replies = session .liveliness() .get(&key_expr) .timeout(timeout) - .res() .await .unwrap(); while let Ok(reply) = replies.recv_async().await { diff --git a/examples/examples/z_info.rs b/examples/examples/z_info.rs index 9525a7abf1..58064461d4 100644 --- a/examples/examples/z_info.rs +++ b/examples/examples/z_info.rs @@ -24,17 +24,17 @@ async fn main() { let config = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); let info = session.info(); - println!("zid: {}", info.zid().res().await); + println!("zid: {}", info.zid().await); println!( "routers zid: {:?}", - info.routers_zid().res().await.collect::>() + info.routers_zid().await.collect::>() ); println!( "peers zid: {:?}", - info.peers_zid().res().await.collect::>() + info.peers_zid().await.collect::>() ); } diff --git a/examples/examples/z_liveliness.rs b/examples/examples/z_liveliness.rs index f82d62e8bd..85b41a0299 100644 --- a/examples/examples/z_liveliness.rs +++ b/examples/examples/z_liveliness.rs @@ -24,17 +24,10 @@ async fn main() { let (config, key_expr) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring LivelinessToken on '{}'...", &key_expr); - let mut token = Some( - session - .liveliness() - .declare_token(&key_expr) - .res() - .await - .unwrap(), - ); + let mut token = Some(session.liveliness().declare_token(&key_expr).await.unwrap()); println!("Press CTRL-C to undeclare LivelinessToken and quit..."); std::thread::park(); @@ -42,7 +35,7 @@ async fn main() { // Use the code below to manually undeclare it if needed if let Some(token) = token.take() { println!("Undeclaring LivelinessToken..."); - token.undeclare().res().await.unwrap(); + token.undeclare().await.unwrap(); }; } diff --git a/examples/examples/z_pub.rs b/examples/examples/z_pub.rs index e91d183b92..2954485784 100644 --- a/examples/examples/z_pub.rs +++ b/examples/examples/z_pub.rs @@ -25,22 +25,17 @@ async fn main() { let (config, key_expr, value, attachment) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Publisher on '{key_expr}'..."); - let publisher = session.declare_publisher(&key_expr).res().await.unwrap(); + let publisher = session.declare_publisher(&key_expr).await.unwrap(); println!("Press CTRL-C to quit..."); for idx in 0..u32::MAX { tokio::time::sleep(Duration::from_secs(1)).await; let buf = format!("[{idx:4}] {value}"); println!("Putting Data ('{}': '{}')...", &key_expr, buf); - publisher - .put(buf) - .attachment(&attachment) - .res() - .await - .unwrap(); + publisher.put(buf).attachment(&attachment).await.unwrap(); } } diff --git a/examples/examples/z_pub_shm.rs b/examples/examples/z_pub_shm.rs index fa72714741..bdd44d5ae7 100644 --- a/examples/examples/z_pub_shm.rs +++ b/examples/examples/z_pub_shm.rs @@ -34,14 +34,14 @@ async fn main() -> Result<(), zenoh::Error> { config.transport.shared_memory.set_enabled(true).unwrap(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Creating Shared Memory Manager..."); let id = session.zid(); let mut shm = SharedMemoryManager::make(id.to_string(), N * 1024).unwrap(); println!("Allocating Shared Memory Buffer..."); - let publisher = session.declare_publisher(&path).res().await.unwrap(); + let publisher = session.declare_publisher(&path).await.unwrap(); println!("Press CTRL-C to quit..."); for idx in 0..(K * N as u32) { @@ -88,7 +88,7 @@ async fn main() -> Result<(), zenoh::Error> { path, String::from_utf8_lossy(&slice[0..slice_len]) ); - publisher.put(sbuf.clone()).res().await?; + publisher.put(sbuf.clone()).await?; if idx % K == 0 { let freed = shm.garbage_collect(); println!("The Gargabe collector freed {freed} bytes"); diff --git a/examples/examples/z_pub_shm_thr.rs b/examples/examples/z_pub_shm_thr.rs index 8917eda74d..97c2119605 100644 --- a/examples/examples/z_pub_shm_thr.rs +++ b/examples/examples/z_pub_shm_thr.rs @@ -29,7 +29,7 @@ async fn main() { // subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected. config.transport.shared_memory.set_enabled(true).unwrap(); - let z = zenoh::open(config).res().await.unwrap(); + let z = zenoh::open(config).await.unwrap(); let id = z.zid(); let mut shm = SharedMemoryManager::make(id.to_string(), sm_size).unwrap(); let mut buf = shm.alloc(size).unwrap(); @@ -40,11 +40,11 @@ async fn main() { let publisher = z.declare_publisher("test/thr") // Make sure to not drop messages because of congestion control - .congestion_control(CongestionControl::Block).res().await.unwrap(); + .congestion_control(CongestionControl::Block).await.unwrap(); println!("Press CTRL-C to quit..."); loop { - publisher.put(buf.clone()).res().await.unwrap(); + publisher.put(buf.clone()).await.unwrap(); } } diff --git a/examples/examples/z_pull.rs b/examples/examples/z_pull.rs index 0169b6844d..15d94cdea0 100644 --- a/examples/examples/z_pull.rs +++ b/examples/examples/z_pull.rs @@ -24,13 +24,12 @@ async fn main() { let (config, key_expr, size, interval) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Subscriber on '{key_expr}'..."); let subscriber = session .declare_subscriber(&key_expr) .with(RingChannel::new(size)) - .res() .await .unwrap(); diff --git a/examples/examples/z_put.rs b/examples/examples/z_put.rs index eeab4647d8..710e086f5d 100644 --- a/examples/examples/z_put.rs +++ b/examples/examples/z_put.rs @@ -24,10 +24,10 @@ async fn main() { let (config, key_expr, value) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Putting Data ('{key_expr}': '{value}')..."); - session.put(&key_expr, value).res().await.unwrap(); + session.put(&key_expr, value).await.unwrap(); } #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] diff --git a/examples/examples/z_put_float.rs b/examples/examples/z_put_float.rs index ff34a7a4ba..1417614997 100644 --- a/examples/examples/z_put_float.rs +++ b/examples/examples/z_put_float.rs @@ -24,12 +24,12 @@ async fn main() { let (config, key_expr, value) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Putting Float ('{key_expr}': '{value}')..."); - session.put(&key_expr, value).res().await.unwrap(); + session.put(&key_expr, value).await.unwrap(); - session.close().res().await.unwrap(); + session.close().await.unwrap(); } #[derive(clap::Parser, Clone, PartialEq, Debug)] diff --git a/examples/examples/z_queryable.rs b/examples/examples/z_queryable.rs index f98042c44c..9036c3b3f3 100644 --- a/examples/examples/z_queryable.rs +++ b/examples/examples/z_queryable.rs @@ -24,7 +24,7 @@ async fn main() { let (config, key_expr, value, complete) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Queryable on '{key_expr}'..."); let queryable = session @@ -34,7 +34,6 @@ async fn main() { // // More information on the ring channel are available in the z_pull example. // .with(zenoh::handlers::RingChannel::default()) .complete(complete) - .res() .await .unwrap(); @@ -61,7 +60,6 @@ async fn main() { ); query .reply(key_expr.clone(), value.clone()) - .res() .await .unwrap_or_else(|e| println!(">> [Queryable ] Error sending reply: {e}")); } diff --git a/examples/examples/z_scout.rs b/examples/examples/z_scout.rs index 2f4e0bf7d1..ff9913def9 100644 --- a/examples/examples/z_scout.rs +++ b/examples/examples/z_scout.rs @@ -22,7 +22,6 @@ async fn main() { println!("Scouting..."); let receiver = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, Config::default()) - .res() .await .unwrap(); diff --git a/examples/examples/z_storage.rs b/examples/examples/z_storage.rs index 0faba7a84e..5a97b4a26d 100644 --- a/examples/examples/z_storage.rs +++ b/examples/examples/z_storage.rs @@ -30,16 +30,15 @@ async fn main() { let mut stored: HashMap = HashMap::new(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Subscriber on '{key_expr}'..."); - let subscriber = session.declare_subscriber(&key_expr).res().await.unwrap(); + let subscriber = session.declare_subscriber(&key_expr).await.unwrap(); println!("Declaring Queryable on '{key_expr}'..."); let queryable = session .declare_queryable(&key_expr) .complete(complete) - .res() .await .unwrap(); @@ -61,7 +60,7 @@ async fn main() { println!(">> [Queryable ] Received Query '{}'", query.selector()); for (stored_name, sample) in stored.iter() { if query.selector().key_expr().intersects(unsafe {keyexpr::from_str_unchecked(stored_name)}) { - query.reply(sample.key_expr().clone(), sample.payload().clone()).res().await.unwrap(); + query.reply(sample.key_expr().clone(), sample.payload().clone()).await.unwrap(); } } } diff --git a/examples/examples/z_sub.rs b/examples/examples/z_sub.rs index de2cde4221..8c72159c38 100644 --- a/examples/examples/z_sub.rs +++ b/examples/examples/z_sub.rs @@ -29,10 +29,10 @@ async fn main() { config.transport.shared_memory.set_enabled(true).unwrap(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Subscriber on '{}'...", &key_expr); - let subscriber = session.declare_subscriber(&key_expr).res().await.unwrap(); + let subscriber = session.declare_subscriber(&key_expr).await.unwrap(); println!("Press CTRL-C to quit..."); while let Ok(sample) = subscriber.recv_async().await { diff --git a/examples/examples/z_sub_liveliness.rs b/examples/examples/z_sub_liveliness.rs index 8d33045515..f4b28e5b62 100644 --- a/examples/examples/z_sub_liveliness.rs +++ b/examples/examples/z_sub_liveliness.rs @@ -24,14 +24,13 @@ async fn main() { let (config, key_expr) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Liveliness Subscriber on '{}'...", &key_expr); let subscriber = session .liveliness() .declare_subscriber(&key_expr) - .res() .await .unwrap(); diff --git a/examples/examples/z_sub_shm.rs b/examples/examples/z_sub_shm.rs index f89df5ee60..165c3ffca2 100644 --- a/examples/examples/z_sub_shm.rs +++ b/examples/examples/z_sub_shm.rs @@ -30,10 +30,10 @@ async fn main() { config.transport.shared_memory.set_enabled(true).unwrap(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Subscriber on '{}'...", &key_expr); - let subscriber = session.declare_subscriber(&key_expr).res().await.unwrap(); + let subscriber = session.declare_subscriber(&key_expr).await.unwrap(); println!("Press CTRL-C to quit..."); while let Ok(sample) = subscriber.recv_async().await { diff --git a/plugins/zenoh-plugin-example/src/lib.rs b/plugins/zenoh-plugin-example/src/lib.rs index c2112e28b2..35ae2c2804 100644 --- a/plugins/zenoh-plugin-example/src/lib.rs +++ b/plugins/zenoh-plugin-example/src/lib.rs @@ -144,7 +144,7 @@ async fn run(runtime: Runtime, selector: KeyExpr<'_>, flag: Arc) { zenoh_util::init_log_from_env(); // create a zenoh Session that shares the same Runtime than zenohd - let session = zenoh::init(runtime).res().await.unwrap(); + let session = zenoh::init(runtime).await.unwrap(); // the HasMap used as a storage by this example of storage plugin let mut stored: HashMap = HashMap::new(); @@ -153,11 +153,11 @@ async fn run(runtime: Runtime, selector: KeyExpr<'_>, flag: Arc) { // This storage plugin subscribes to the selector and will store in HashMap the received samples debug!("Create Subscriber on {}", selector); - let sub = session.declare_subscriber(&selector).res().await.unwrap(); + let sub = session.declare_subscriber(&selector).await.unwrap(); // This storage plugin declares a Queryable that will reply to queries with the samples stored in the HashMap debug!("Create Queryable on {}", selector); - let queryable = session.declare_queryable(&selector).res().await.unwrap(); + let queryable = session.declare_queryable(&selector).await.unwrap(); // Plugin's event loop, while the flag is true while flag.load(Relaxed) { @@ -175,7 +175,7 @@ async fn run(runtime: Runtime, selector: KeyExpr<'_>, flag: Arc) { info!("Handling query '{}'", query.selector()); for (key_expr, sample) in stored.iter() { if query.selector().key_expr().intersects(unsafe{keyexpr::from_str_unchecked(key_expr)}) { - query.reply_sample(sample.clone()).res().await.unwrap(); + query.reply_sample(sample.clone()).await.unwrap(); } } } diff --git a/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs b/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs index 287ef77e1c..75264d802c 100644 --- a/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs +++ b/plugins/zenoh-plugin-rest/examples/z_serve_sse.rs @@ -40,16 +40,16 @@ async fn main() { let value = "Pub from sse server!"; println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring Queryable on '{key}'..."); - let queryable = session.declare_queryable(key).res().await.unwrap(); + let queryable = session.declare_queryable(key).await.unwrap(); async_std::task::spawn({ let receiver = queryable.handler().clone(); async move { while let Ok(request) = receiver.recv_async().await { - request.reply(key, HTML).res().await.unwrap(); + request.reply(key, HTML).await.unwrap(); } } }); @@ -60,7 +60,6 @@ async fn main() { let publisher = session .declare_publisher(&event_key) .congestion_control(CongestionControl::Block) - .res() .await .unwrap(); @@ -71,7 +70,7 @@ async fn main() { println!("Data updates are accessible through HTML5 SSE at http://:8000/{key}"); loop { - publisher.put(value).res().await.unwrap(); + publisher.put(value).await.unwrap(); async_std::task::sleep(Duration::from_secs(1)).await; } } diff --git a/plugins/zenoh-plugin-rest/src/lib.rs b/plugins/zenoh-plugin-rest/src/lib.rs index c9397aa4a9..d4766f7c4e 100644 --- a/plugins/zenoh-plugin-rest/src/lib.rs +++ b/plugins/zenoh-plugin-rest/src/lib.rs @@ -346,13 +346,7 @@ async fn query(mut req: Request<(Arc, String)>) -> tide::Result, String)>) -> tide::Result, String)>) -> tide::Result, String)>) -> tide::Result { if raw { Ok(to_raw_response(receiver).await) @@ -466,8 +460,8 @@ async fn write(mut req: Request<(Arc, String)>) -> tide::Result session.put(&key_expr, bytes).encoding(encoding).res().await, - SampleKind::Delete => session.delete(&key_expr).res().await, + SampleKind::Put => session.put(&key_expr, bytes).encoding(encoding).await, + SampleKind::Delete => session.delete(&key_expr).await, }; match res { Ok(_) => Ok(Response::new(StatusCode::Ok)), @@ -493,7 +487,7 @@ pub async fn run(runtime: Runtime, conf: Config) -> ZResult<()> { zenoh_util::init_log_from_env(); let zid = runtime.zid().to_string(); - let session = zenoh::init(runtime).res().await.unwrap(); + let session = zenoh::init(runtime).await.unwrap(); let mut app = Server::with_state((Arc::new(session), zid)); app.with( diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs b/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs index f3f8ade729..0b00f7bbee 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/align_queryable.rs @@ -71,7 +71,6 @@ impl AlignQueryable { .session .declare_queryable(&self.digest_key) .complete(true) // This queryable is meant to have all the history - .res() .await .unwrap(); @@ -100,7 +99,6 @@ impl AlignQueryable { query.key_expr().clone(), serde_json::to_string(&(i, c)).unwrap(), ) - .res() .await .unwrap(); } @@ -110,7 +108,6 @@ impl AlignQueryable { query.key_expr().clone(), serde_json::to_string(&(i, c)).unwrap(), ) - .res() .await .unwrap(); } @@ -120,7 +117,6 @@ impl AlignQueryable { query.key_expr().clone(), serde_json::to_string(&(i, c)).unwrap(), ) - .res() .await .unwrap(); } @@ -129,7 +125,6 @@ impl AlignQueryable { .reply(k, v.payload().clone()) .encoding(v.encoding().clone()) .timestamp(ts) - .res() .await .unwrap(); } @@ -229,7 +224,7 @@ impl AlignQueryable { impl AlignQueryable { async fn get_entry(&self, logentry: &LogEntry) -> Option { // get corresponding key from log - let replies = self.session.get(&logentry.key).res().await.unwrap(); + let replies = self.session.get(&logentry.key).await.unwrap(); if let Ok(reply) = replies.recv_async().await { match reply.into_result() { Ok(sample) => { diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs b/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs index c1dc1196bf..b15c667694 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs @@ -327,7 +327,6 @@ impl Aligner { .get(&selector) .consolidation(zenoh::query::ConsolidationMode::None) .accept_replies(zenoh::query::ReplyKeyExpr::Any) - .res() .await { Ok(replies) => { diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs index 525d446f3a..f214ac89f7 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs @@ -209,7 +209,6 @@ impl Replica { .session .declare_subscriber(&digest_key) .allowed_origin(Locality::Remote) - .res() .await .unwrap(); loop { @@ -271,7 +270,6 @@ impl Replica { let publisher = self .session .declare_publisher(digest_key) - .res() .await .unwrap(); @@ -287,7 +285,7 @@ impl Replica { drop(digest); tracing::trace!("[DIGEST_PUB] Putting Digest: {} ...", digest_json); - match publisher.put(digest_json).res().await { + match publisher.put(digest_json).await { Ok(()) => {} Err(e) => tracing::error!("[DIGEST_PUB] Digest publication failed: {}", e), } diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs index 14425f4c28..4c39df6207 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs @@ -141,7 +141,7 @@ impl StorageService { t.add_async(gc).await; // subscribe on key_expr - let storage_sub = match self.session.declare_subscriber(&self.key_expr).res().await { + let storage_sub = match self.session.declare_subscriber(&self.key_expr).await { Ok(storage_sub) => storage_sub, Err(e) => { tracing::error!("Error starting storage '{}': {}", self.name, e); @@ -154,7 +154,6 @@ impl StorageService { .session .declare_queryable(&self.key_expr) .complete(self.complete) - .res() .await { Ok(storage_queryable) => storage_queryable, @@ -519,7 +518,6 @@ impl StorageService { .reply(key.clone(), entry.value.payload().clone()) .encoding(entry.value.encoding().clone()) .timestamp(entry.timestamp) - .res() .await { tracing::warn!( @@ -553,7 +551,6 @@ impl StorageService { .reply(q.key_expr().clone(), entry.value.payload().clone()) .encoding(entry.value.encoding().clone()) .timestamp(entry.timestamp) - .res() .await { tracing::warn!( @@ -641,7 +638,6 @@ impl StorageService { .get(KeyExpr::from(&self.key_expr).with_parameters("_time=[..]")) .target(QueryTarget::All) .consolidation(ConsolidationMode::None) - .res() .await { Ok(replies) => replies, diff --git a/plugins/zenoh-plugin-storage-manager/tests/operations.rs b/plugins/zenoh-plugin-storage-manager/tests/operations.rs index c82459cdcc..9b25099205 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/operations.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/operations.rs @@ -30,23 +30,17 @@ use zenoh_plugin_trait::Plugin; async fn put_data(session: &zenoh::Session, key_expr: &str, value: &str, _timestamp: Timestamp) { println!("Putting Data ('{key_expr}': '{value}')..."); // @TODO: how to add timestamp metadata with put, not manipulating sample... - session.put(key_expr, value).res().await.unwrap(); + session.put(key_expr, value).await.unwrap(); } async fn delete_data(session: &zenoh::Session, key_expr: &str, _timestamp: Timestamp) { println!("Deleting Data '{key_expr}'..."); // @TODO: how to add timestamp metadata with delete, not manipulating sample... - session.delete(key_expr).res().await.unwrap(); + session.delete(key_expr).await.unwrap(); } async fn get_data(session: &zenoh::Session, key_expr: &str) -> Vec { - let replies: Vec = session - .get(key_expr) - .res() - .await - .unwrap() - .into_iter() - .collect(); + let replies: Vec = session.get(key_expr).await.unwrap().into_iter().collect(); println!("Getting replies on '{key_expr}': '{replies:?}'..."); let mut samples = Vec::new(); for reply in replies { @@ -83,7 +77,7 @@ async fn test_updates_in_order() { let storage = zenoh_plugin_storage_manager::StoragesPlugin::start("storage-manager", &runtime).unwrap(); - let session = zenoh::init(runtime).res().await.unwrap(); + let session = zenoh::init(runtime).await.unwrap(); sleep(std::time::Duration::from_secs(1)); diff --git a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs index d778eadde4..0d2a3eb477 100644 --- a/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs +++ b/plugins/zenoh-plugin-storage-manager/tests/wildcard.rs @@ -31,23 +31,17 @@ use zenoh_plugin_trait::Plugin; async fn put_data(session: &zenoh::Session, key_expr: &str, value: &str, _timestamp: Timestamp) { println!("Putting Data ('{key_expr}': '{value}')..."); // @TODO: how to add timestamp metadata with put, not manipulating sample... - session.put(key_expr, value).res().await.unwrap(); + session.put(key_expr, value).await.unwrap(); } async fn delete_data(session: &zenoh::Session, key_expr: &str, _timestamp: Timestamp) { println!("Deleting Data '{key_expr}'..."); // @TODO: how to add timestamp metadata with delete, not manipulating sample... - session.delete(key_expr).res().await.unwrap(); + session.delete(key_expr).await.unwrap(); } async fn get_data(session: &zenoh::Session, key_expr: &str) -> Vec { - let replies: Vec = session - .get(key_expr) - .res() - .await - .unwrap() - .into_iter() - .collect(); + let replies: Vec = session.get(key_expr).await.unwrap().into_iter().collect(); println!("Getting replies on '{key_expr}': '{replies:?}'..."); let mut samples = Vec::new(); for reply in replies { @@ -84,7 +78,7 @@ async fn test_wild_card_in_order() { let storage = zenoh_plugin_storage_manager::StoragesPlugin::start("storage-manager", &runtime).unwrap(); - let session = zenoh::init(runtime).res().await.unwrap(); + let session = zenoh::init(runtime).await.unwrap(); sleep(std::time::Duration::from_secs(1)); // put *, ts: 1 diff --git a/zenoh-ext/examples/examples/z_member.rs b/zenoh-ext/examples/examples/z_member.rs index f660482a3c..b8c6d80a40 100644 --- a/zenoh-ext/examples/examples/z_member.rs +++ b/zenoh-ext/examples/examples/z_member.rs @@ -21,7 +21,7 @@ use zenoh_ext::group::*; #[tokio::main] async fn main() { zenoh_util::init_log_from_env(); - let z = Arc::new(zenoh::open(Config::default()).res().await.unwrap()); + let z = Arc::new(zenoh::open(Config::default()).await.unwrap()); let member = Member::new(z.zid().to_string()) .unwrap() .lease(Duration::from_secs(3)); diff --git a/zenoh-ext/examples/examples/z_pub_cache.rs b/zenoh-ext/examples/examples/z_pub_cache.rs index 332e3f7822..bf20029773 100644 --- a/zenoh-ext/examples/examples/z_pub_cache.rs +++ b/zenoh-ext/examples/examples/z_pub_cache.rs @@ -26,7 +26,7 @@ async fn main() { let (config, key_expr, value, history, prefix, complete) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!("Declaring PublicationCache on {}", &key_expr); let mut publication_cache_builder = session @@ -36,14 +36,14 @@ async fn main() { if let Some(prefix) = prefix { publication_cache_builder = publication_cache_builder.queryable_prefix(prefix); } - let _publication_cache = publication_cache_builder.res().await.unwrap(); + let _publication_cache = publication_cache_builder.await.unwrap(); println!("Press CTRL-C to quit..."); for idx in 0..u32::MAX { tokio::time::sleep(Duration::from_secs(1)).await; let buf = format!("[{idx:4}] {value}"); println!("Put Data ('{}': '{}')", &key_expr, buf); - session.put(&key_expr, buf).res().await.unwrap(); + session.put(&key_expr, buf).await.unwrap(); } } diff --git a/zenoh-ext/examples/examples/z_query_sub.rs b/zenoh-ext/examples/examples/z_query_sub.rs index e5d2e4cf78..5801fee185 100644 --- a/zenoh-ext/examples/examples/z_query_sub.rs +++ b/zenoh-ext/examples/examples/z_query_sub.rs @@ -27,7 +27,7 @@ async fn main() { let (config, key_expr, query) = parse_args(); println!("Opening session..."); - let session = zenoh::open(config).res().await.unwrap(); + let session = zenoh::open(config).await.unwrap(); println!( "Declaring QueryingSubscriber on {} with an initial query on {}", @@ -40,14 +40,12 @@ async fn main() { .querying() .query_selector(&selector) .query_accept_replies(ReplyKeyExpr::Any) - .res() .await .unwrap() } else { session .declare_subscriber(key_expr) .querying() - .res() .await .unwrap() }; diff --git a/zenoh-ext/examples/examples/z_view_size.rs b/zenoh-ext/examples/examples/z_view_size.rs index a7d95ae603..12051df306 100644 --- a/zenoh-ext/examples/examples/z_view_size.rs +++ b/zenoh-ext/examples/examples/z_view_size.rs @@ -25,7 +25,7 @@ async fn main() { let (config, group_name, id, size, timeout) = parse_args(); - let z = Arc::new(zenoh::open(config).res().await.unwrap()); + let z = Arc::new(zenoh::open(config).await.unwrap()); let member_id = id.unwrap_or_else(|| z.zid().to_string()); let member = Member::new(member_id.as_str()) .unwrap() diff --git a/zenoh-ext/src/group.rs b/zenoh-ext/src/group.rs index 0926c63d33..e08d814ba1 100644 --- a/zenoh-ext/src/group.rs +++ b/zenoh-ext/src/group.rs @@ -185,7 +185,7 @@ async fn keep_alive_task(state: Arc) { loop { tokio::time::sleep(period).await; tracing::trace!("Sending Keep Alive for: {}", &state.local_member.mid); - let _ = state.group_publisher.put(buf.clone()).res().await; + let _ = state.group_publisher.put(buf.clone()).await; } } @@ -227,18 +227,17 @@ async fn query_handler(z: Arc, state: Arc) { .unwrap(); tracing::debug!("Started query handler for: {}", &qres); let buf = bincode::serialize(&state.local_member).unwrap(); - let queryable = z.declare_queryable(&qres).res().await.unwrap(); + let queryable = z.declare_queryable(&qres).await.unwrap(); while let Ok(query) = queryable.recv_async().await { tracing::trace!("Serving query for: {}", &qres); - query.reply(qres.clone(), buf.clone()).res().await.unwrap(); + query.reply(qres.clone(), buf.clone()).await.unwrap(); } } async fn net_event_handler(z: Arc, state: Arc) { let sub = z .declare_subscriber(state.group_publisher.key_expr()) - .res() .await .unwrap(); while let Ok(s) = sub.recv_async().await { @@ -296,7 +295,7 @@ async fn net_event_handler(z: Arc, state: Arc) { // @TODO: we could also send this member info let qc = ConsolidationMode::None; tracing::trace!("Issuing Query for {}", &qres); - let receiver = z.get(&qres).consolidation(qc).res().await.unwrap(); + let receiver = z.get(&qres).consolidation(qc).await.unwrap(); while let Ok(reply) = receiver.recv_async().await { match reply.result() { @@ -366,7 +365,6 @@ impl Group { let publisher = z .declare_publisher(event_expr) .priority(with.priority) - .res() .await .unwrap(); let state = Arc::new(GroupState { @@ -383,7 +381,7 @@ impl Group { tracing::debug!("Sending Join Message for local member: {:?}", &with); let join_evt = GroupNetEvent::Join(JoinEvent { member: with }); let buf = bincode::serialize(&join_evt).unwrap(); - let _ = state.group_publisher.put(buf).res().await; + let _ = state.group_publisher.put(buf).await; let task_controller = TaskController::default(); // If the liveliness is manual it is the user who has to assert it. diff --git a/zenoh-ext/src/publication_cache.rs b/zenoh-ext/src/publication_cache.rs index c8938d6c74..ec53e4f2bf 100644 --- a/zenoh-ext/src/publication_cache.rs +++ b/zenoh-ext/src/publication_cache.rs @@ -19,7 +19,7 @@ use zenoh::prelude::r#async::*; use zenoh::queryable::{Query, Queryable}; use zenoh::subscriber::FlumeSubscriber; use zenoh::SessionRef; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use zenoh_core::{Resolvable, SyncResolve}; use zenoh_result::{bail, ZResult}; use zenoh_task::TerminatableTask; use zenoh_util::core::ResolveFuture; @@ -100,10 +100,11 @@ impl SyncResolve for PublicationCacheBuilder<'_, '_, '_> { } } -impl<'a> AsyncResolve for PublicationCacheBuilder<'a, '_, '_> { - type Future = Ready; +impl<'a> IntoFuture for PublicationCacheBuilder<'a, '_, '_> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -213,7 +214,7 @@ impl<'a> PublicationCache<'a> { continue; } } - if let Err(e) = query.reply_sample(sample.clone()).res_async().await { + if let Err(e) = query.reply_sample(sample.clone()).await { tracing::warn!("Error replying to query: {}", e); } } @@ -227,7 +228,7 @@ impl<'a> PublicationCache<'a> { continue; } } - if let Err(e) = query.reply_sample(sample.clone()).res_async().await { + if let Err(e) = query.reply_sample(sample.clone()).await { tracing::warn!("Error replying to query: {}", e); } } @@ -259,8 +260,8 @@ impl<'a> PublicationCache<'a> { local_sub, task, } = self; - _queryable.undeclare().res_async().await?; - local_sub.undeclare().res_async().await?; + _queryable.undeclare().await?; + local_sub.undeclare().await?; task.terminate(Duration::from_secs(10)); Ok(()) }) diff --git a/zenoh-ext/src/querying_subscriber.rs b/zenoh-ext/src/querying_subscriber.rs index 1a6b707571..8473cfede8 100644 --- a/zenoh-ext/src/querying_subscriber.rs +++ b/zenoh-ext/src/querying_subscriber.rs @@ -25,7 +25,7 @@ use zenoh::subscriber::{Reliability, Subscriber}; use zenoh::time::{new_reception_timestamp, Timestamp}; use zenoh::Result as ZResult; use zenoh::SessionRef; -use zenoh_core::{zlock, AsyncResolve, Resolvable, SyncResolve}; +use zenoh_core::{zlock, Resolvable, SyncResolve}; use crate::ExtractSample; @@ -270,15 +270,16 @@ where } } -impl<'a, KeySpace, Handler> AsyncResolve for QueryingSubscriberBuilder<'a, '_, KeySpace, Handler> +impl<'a, KeySpace, Handler> IntoFuture for QueryingSubscriberBuilder<'a, '_, KeySpace, Handler> where KeySpace: Into + Clone, Handler: IntoHandler<'static, Sample> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -567,16 +568,17 @@ impl< Handler, Fetch: FnOnce(Box) -> ZResult<()> + Send + Sync, TryIntoSample, - > AsyncResolve for FetchingSubscriberBuilder<'a, '_, KeySpace, Handler, Fetch, TryIntoSample> + > IntoFuture for FetchingSubscriberBuilder<'a, '_, KeySpace, Handler, Fetch, TryIntoSample> where KeySpace: Into, Handler: IntoHandler<'static, Sample> + Send, Handler::Handler: Send, TryIntoSample: ExtractSample + Send + Sync, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -596,7 +598,7 @@ where /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expr") /// .fetching( |cb| { @@ -606,7 +608,6 @@ where /// .callback(cb) /// .res_sync() /// }) -/// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -733,7 +734,7 @@ impl<'a, Handler> FetchingSubscriber<'a, Handler> { /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let mut subscriber = session /// .declare_subscriber("key/expr") /// .fetching( |cb| { @@ -743,7 +744,6 @@ impl<'a, Handler> FetchingSubscriber<'a, Handler> { /// .callback(cb) /// .res_sync() /// }) - /// .res() /// .await /// .unwrap(); /// @@ -756,7 +756,6 @@ impl<'a, Handler> FetchingSubscriber<'a, Handler> { /// .callback(cb) /// .res_sync() /// }) - /// .res() /// .await /// .unwrap(); /// # } @@ -815,7 +814,7 @@ impl Drop for RepliesHandler { /// # use zenoh::prelude::r#async::*; /// # use zenoh_ext::*; /// # -/// # let session = zenoh::open(config::peer()).res().await.unwrap(); +/// # let session = zenoh::open(config::peer()).await.unwrap(); /// # let mut fetching_subscriber = session /// # .declare_subscriber("key/expr") /// # .fetching( |cb| { @@ -837,7 +836,6 @@ impl Drop for RepliesHandler { /// .callback(cb) /// .res_sync() /// }) -/// .res() /// .await /// .unwrap(); /// # } @@ -875,13 +873,14 @@ where } impl) -> ZResult<()>, TryIntoSample> - AsyncResolve for FetchBuilder + IntoFuture for FetchBuilder where TryIntoSample: ExtractSample, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } diff --git a/zenoh-ext/src/session_ext.rs b/zenoh-ext/src/session_ext.rs index 73fbd7dfc4..e45ccc5f3a 100644 --- a/zenoh-ext/src/session_ext.rs +++ b/zenoh-ext/src/session_ext.rs @@ -65,8 +65,8 @@ impl<'s> SessionExt<'s, 'static> for Arc { /// /// let mut config = config::default(); /// config.timestamping.set_enabled(Some(Unique(true))); - /// let session = zenoh::open(config).res().await.unwrap().into_arc(); - /// let publication_cache = session.declare_publication_cache("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config).await.unwrap().into_arc(); + /// let publication_cache = session.declare_publication_cache("key/expression").await.unwrap(); /// tokio::task::spawn(async move { /// publication_cache.key_expr(); /// }).await; diff --git a/zenoh-ext/src/subscriber_ext.rs b/zenoh-ext/src/subscriber_ext.rs index 4b6346bcf8..788a51afd6 100644 --- a/zenoh-ext/src/subscriber_ext.rs +++ b/zenoh-ext/src/subscriber_ext.rs @@ -63,7 +63,7 @@ pub trait SubscriberBuilderExt<'a, 'b, Handler> { /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expr") /// .fetching( |cb| { @@ -73,7 +73,6 @@ pub trait SubscriberBuilderExt<'a, 'b, Handler> { /// .callback(cb) /// .res_sync() /// }) - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -109,11 +108,10 @@ pub trait SubscriberBuilderExt<'a, 'b, Handler> { /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expr") /// .querying() - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -144,7 +142,7 @@ impl<'a, 'b, Handler> SubscriberBuilderExt<'a, 'b, Handler> for SubscriberBuilde /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expr") /// .fetching( |cb| { @@ -154,7 +152,6 @@ impl<'a, 'b, Handler> SubscriberBuilderExt<'a, 'b, Handler> for SubscriberBuilde /// .callback(cb) /// .res_sync() /// }) - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -202,11 +199,10 @@ impl<'a, 'b, Handler> SubscriberBuilderExt<'a, 'b, Handler> for SubscriberBuilde /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expr") /// .querying() - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -257,7 +253,7 @@ impl<'a, 'b, Handler> SubscriberBuilderExt<'a, 'b, Handler> /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .liveliness() /// .declare_subscriber("key/expr") @@ -269,7 +265,6 @@ impl<'a, 'b, Handler> SubscriberBuilderExt<'a, 'b, Handler> /// .callback(cb) /// .res_sync() /// }) - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -318,12 +313,11 @@ impl<'a, 'b, Handler> SubscriberBuilderExt<'a, 'b, Handler> /// use zenoh::prelude::r#async::*; /// use zenoh_ext::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .liveliness() /// .declare_subscriber("key/expr") /// .querying() - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { diff --git a/zenoh/src/info.rs b/zenoh/src/info.rs index 3e0efdf134..dac1a2294b 100644 --- a/zenoh/src/info.rs +++ b/zenoh/src/info.rs @@ -14,8 +14,8 @@ //! Tools to access information about the current zenoh [`Session`](crate::Session). use crate::SessionRef; -use std::future::Ready; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use std::future::{IntoFuture, Ready}; +use zenoh_core::{Resolvable, SyncResolve}; use zenoh_protocol::core::{WhatAmI, ZenohId}; /// A builder retuned by [`SessionInfo::zid()`](SessionInfo::zid) that allows @@ -27,8 +27,8 @@ use zenoh_protocol::core::{WhatAmI, ZenohId}; /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let zid = session.info().zid().res().await; +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let zid = session.info().zid().await; /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -47,10 +47,11 @@ impl<'a> SyncResolve for ZidBuilder<'a> { } } -impl<'a> AsyncResolve for ZidBuilder<'a> { - type Future = Ready; +impl<'a> IntoFuture for ZidBuilder<'a> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -65,8 +66,8 @@ impl<'a> AsyncResolve for ZidBuilder<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let mut routers_zid = session.info().routers_zid().res().await; +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let mut routers_zid = session.info().routers_zid().await; /// while let Some(router_zid) = routers_zid.next() {} /// # } /// ``` @@ -96,10 +97,11 @@ impl<'a> SyncResolve for RoutersZidBuilder<'a> { } } -impl<'a> AsyncResolve for RoutersZidBuilder<'a> { - type Future = Ready; +impl<'a> IntoFuture for RoutersZidBuilder<'a> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -113,9 +115,9 @@ impl<'a> AsyncResolve for RoutersZidBuilder<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let zid = session.info().zid().res().await; -/// let mut peers_zid = session.info().peers_zid().res().await; +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let zid = session.info().zid().await; +/// let mut peers_zid = session.info().peers_zid().await; /// while let Some(peer_zid) = peers_zid.next() {} /// # } /// ``` @@ -145,10 +147,11 @@ impl<'a> SyncResolve for PeersZidBuilder<'a> { } } -impl<'a> AsyncResolve for PeersZidBuilder<'a> { - type Future = Ready; +impl<'a> IntoFuture for PeersZidBuilder<'a> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -162,9 +165,9 @@ impl<'a> AsyncResolve for PeersZidBuilder<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let info = session.info(); -/// let zid = info.zid().res().await; +/// let zid = info.zid().await; /// # } /// ``` pub struct SessionInfo<'a> { @@ -180,8 +183,8 @@ impl SessionInfo<'_> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let zid = session.info().zid().res().await; + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let zid = session.info().zid().await; /// # } /// ``` pub fn zid(&self) -> ZidBuilder<'_> { @@ -199,8 +202,8 @@ impl SessionInfo<'_> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let mut routers_zid = session.info().routers_zid().res().await; + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let mut routers_zid = session.info().routers_zid().await; /// while let Some(router_zid) = routers_zid.next() {} /// # } /// ``` @@ -218,8 +221,8 @@ impl SessionInfo<'_> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let mut peers_zid = session.info().peers_zid().res().await; + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let mut peers_zid = session.info().peers_zid().await; /// while let Some(peer_zid) = peers_zid.next() {} /// # } /// ``` diff --git a/zenoh/src/key_expr.rs b/zenoh/src/key_expr.rs index c1c0504208..734f0396c4 100644 --- a/zenoh/src/key_expr.rs +++ b/zenoh/src/key_expr.rs @@ -43,12 +43,13 @@ //! [`kedefine`] also allows you to define formats at compile time, allowing a more performant, but more importantly safer and more convenient use of said formats, //! as the [`keformat`] and [`kewrite`] macros will be able to tell you if you're attempting to set fields of the format that do not exist. +use std::future::IntoFuture; use std::{ convert::{TryFrom, TryInto}, future::Ready, str::FromStr, }; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use zenoh_core::{Resolvable, SyncResolve}; pub use zenoh_keyexpr::*; pub use zenoh_macros::{kedefine, keformat, kewrite}; use zenoh_protocol::{ @@ -610,9 +611,9 @@ impl<'a> Undeclarable<&'a Session, KeyExprUndeclaration<'a>> for KeyExpr<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let key_expr = session.declare_keyexpr("key/expression").res().await.unwrap(); -/// session.undeclare(key_expr).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let key_expr = session.declare_keyexpr("key/expression").await.unwrap(); +/// session.undeclare(key_expr).await.unwrap(); /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -675,10 +676,11 @@ impl SyncResolve for KeyExprUndeclaration<'_> { } } -impl AsyncResolve for KeyExprUndeclaration<'_> { - type Future = Ready; +impl IntoFuture for KeyExprUndeclaration<'_> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 8de143fd8d..ac430a7dc5 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -36,9 +36,9 @@ //! //! #[tokio::main] //! async fn main() { -//! let session = zenoh::open(config::default()).res().await.unwrap(); -//! session.put("key/expression", "value").res().await.unwrap(); -//! session.close().res().await.unwrap(); +//! let session = zenoh::open(config::default()).await.unwrap(); +//! session.put("key/expression", "value").await.unwrap(); +//! session.close().await.unwrap(); //! } //! ``` //! @@ -50,8 +50,8 @@ //! //! #[tokio::main] //! async fn main() { -//! let session = zenoh::open(config::default()).res().await.unwrap(); -//! let subscriber = session.declare_subscriber("key/expression").res().await.unwrap(); +//! let session = zenoh::open(config::default()).await.unwrap(); +//! let subscriber = session.declare_subscriber("key/expression").await.unwrap(); //! while let Ok(sample) = subscriber.recv_async().await { //! println!("Received: {:?}", sample); //! }; @@ -67,8 +67,8 @@ //! //! #[tokio::main] //! async fn main() { -//! let session = zenoh::open(config::default()).res().await.unwrap(); -//! let replies = session.get("key/expression").res().await.unwrap(); +//! let session = zenoh::open(config::default()).await.unwrap(); +//! let replies = session.get("key/expression").await.unwrap(); //! while let Ok(reply) = replies.recv_async().await { //! println!(">> Received {:?}", reply.result()); //! } @@ -87,8 +87,8 @@ use handlers::DefaultHandler; use net::runtime::Runtime; use prelude::*; use scouting::ScoutBuilder; -use std::future::Ready; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use std::future::{IntoFuture, Ready}; +use zenoh_core::{Resolvable, SyncResolve}; pub use zenoh_macros::{ke, kedefine, keformat, kewrite}; use zenoh_protocol::core::WhatAmIMatcher; use zenoh_result::{zerror, ZResult}; @@ -194,7 +194,6 @@ pub mod scouting; /// use zenoh::scouting::WhatAmI; /// /// let receiver = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) -/// .res() /// .await /// .unwrap(); /// while let Ok(hello) = receiver.recv_async().await { @@ -230,7 +229,7 @@ where /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// # } /// ``` /// @@ -244,7 +243,7 @@ where /// config.set_id(ZenohId::from_str("221b72df20924c15b8794c6bdb471150").unwrap()); /// config.connect.endpoints.extend("tcp/10.10.10.10:7447,tcp/11.11.11.11:7447".split(',').map(|s|s.parse().unwrap())); /// -/// let session = zenoh::open(config).res().await.unwrap(); +/// let session = zenoh::open(config).await.unwrap(); /// # } /// ``` pub fn open(config: TryIntoConfig) -> OpenBuilder @@ -263,7 +262,7 @@ where /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -297,14 +296,15 @@ where } } -impl AsyncResolve for OpenBuilder +impl IntoFuture for OpenBuilder where TryIntoConfig: std::convert::TryInto + Send + 'static, >::Error: std::fmt::Debug, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -364,10 +364,11 @@ impl SyncResolve for InitBuilder { } #[zenoh_macros::unstable] -impl AsyncResolve for InitBuilder { - type Future = Ready; +impl IntoFuture for InitBuilder { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } diff --git a/zenoh/src/liveliness.rs b/zenoh/src/liveliness.rs index 33022debbe..8a10424bb8 100644 --- a/zenoh/src/liveliness.rs +++ b/zenoh/src/liveliness.rs @@ -15,6 +15,7 @@ //! Liveliness primitives. //! //! see [`Liveliness`] +use std::future::IntoFuture; use zenoh_protocol::network::request; use crate::{query::Reply, Id}; @@ -33,7 +34,6 @@ use { std::sync::Arc, std::time::Duration, zenoh_config::unwrap_or_default, - zenoh_core::AsyncResolve, zenoh_core::Resolvable, zenoh_core::Result as ZResult, zenoh_core::SyncResolve, @@ -69,11 +69,10 @@ lazy_static::lazy_static!( /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") -/// .res() /// .await /// .unwrap(); /// # } @@ -97,11 +96,10 @@ impl<'a> Liveliness<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") - /// .res() /// .await /// .unwrap(); /// # } @@ -133,8 +131,8 @@ impl<'a> Liveliness<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let subscriber = session.liveliness().declare_subscriber("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let subscriber = session.liveliness().declare_subscriber("key/expression").await.unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { /// match sample.kind() { /// SampleKind::Put => println!("New liveliness: {}", sample.key_expr()), @@ -171,8 +169,8 @@ impl<'a> Liveliness<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let replies = session.liveliness().get("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let replies = session.liveliness().get("key/expression").await.unwrap(); /// while let Ok(reply) = replies.recv_async().await { /// if let Ok(sample) = reply.result() { /// println!(">> Liveliness token {}", sample.key_expr()); @@ -211,11 +209,10 @@ impl<'a> Liveliness<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") -/// .res() /// .await /// .unwrap(); /// # } @@ -250,10 +247,11 @@ impl SyncResolve for LivelinessTokenBuilder<'_, '_> { } #[zenoh_macros::unstable] -impl AsyncResolve for LivelinessTokenBuilder<'_, '_> { - type Future = Ready; +impl IntoFuture for LivelinessTokenBuilder<'_, '_> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -286,11 +284,10 @@ pub(crate) struct LivelinessTokenState { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") -/// .res() /// .await /// .unwrap(); /// # } @@ -311,15 +308,14 @@ pub struct LivelinessToken<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") -/// .res() /// .await /// .unwrap(); /// -/// liveliness.undeclare().res().await.unwrap(); +/// liveliness.undeclare().await.unwrap(); /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -342,10 +338,11 @@ impl SyncResolve for LivelinessTokenUndeclaration<'_> { } #[zenoh_macros::unstable] -impl<'a> AsyncResolve for LivelinessTokenUndeclaration<'a> { - type Future = Ready; +impl<'a> IntoFuture for LivelinessTokenUndeclaration<'a> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -364,15 +361,14 @@ impl<'a> LivelinessToken<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") - /// .res() /// .await /// .unwrap(); /// - /// liveliness.undeclare().res().await.unwrap(); + /// liveliness.undeclare().await.unwrap(); /// # } /// ``` #[inline] @@ -405,11 +401,10 @@ impl Drop for LivelinessToken<'_> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .best_effort() -/// .res() /// .await /// .unwrap(); /// # } @@ -433,11 +428,10 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr(), sample.payload()); }) - /// .res() /// .await /// .unwrap(); /// # } @@ -474,12 +468,11 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let mut n = 0; /// let subscriber = session /// .declare_subscriber("key/expression") /// .callback_mut(move |_sample| { n += 1; }) - /// .res() /// .await /// .unwrap(); /// # } @@ -504,11 +497,10 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -575,15 +567,15 @@ where } #[zenoh_macros::unstable] -impl<'a, Handler> AsyncResolve for LivelinessSubscriberBuilder<'a, '_, Handler> +impl<'a, Handler> IntoFuture for LivelinessSubscriberBuilder<'a, '_, Handler> where Handler: IntoHandler<'static, Sample> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - #[zenoh_macros::unstable] - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -598,11 +590,10 @@ where /// use zenoh::prelude::r#async::*; /// use zenoh::query::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let tokens = session /// .liveliness() /// .get("key/expression") -/// .res() /// .await /// .unwrap(); /// while let Ok(token) = tokens.recv_async().await { @@ -631,12 +622,11 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let queryable = session /// .liveliness() /// .get("key/expression") /// .callback(|reply| { println!("Received {:?}", reply.result()); }) - /// .res() /// .await /// .unwrap(); /// # } @@ -671,13 +661,12 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let mut n = 0; /// let queryable = session /// .liveliness() /// .get("key/expression") /// .callback_mut(move |reply| {n += 1;}) - /// .res() /// .await /// .unwrap(); /// # } @@ -701,12 +690,11 @@ impl<'a, 'b> LivelinessGetBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let replies = session /// .liveliness() /// .get("key/expression") /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// while let Ok(reply) = replies.recv_async().await { @@ -777,14 +765,15 @@ where } } -impl AsyncResolve for LivelinessGetBuilder<'_, '_, Handler> +impl IntoFuture for LivelinessGetBuilder<'_, '_, Handler> where Handler: IntoHandler<'static, Reply> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } diff --git a/zenoh/src/prelude.rs b/zenoh/src/prelude.rs index 9158425034..81abd15567 100644 --- a/zenoh/src/prelude.rs +++ b/zenoh/src/prelude.rs @@ -75,5 +75,5 @@ pub mod sync { /// Prelude to import when using Zenoh's async API. pub mod r#async { pub use super::common::*; - pub use zenoh_core::AsyncResolve; + pub use std::future::IntoFuture; } diff --git a/zenoh/src/publication.rs b/zenoh/src/publication.rs index 303f120360..f9c35552b9 100644 --- a/zenoh/src/publication.rs +++ b/zenoh/src/publication.rs @@ -25,8 +25,8 @@ use crate::{ sample::Attachment, Id, }; -use std::future::Ready; -use zenoh_core::{zread, AsyncResolve, Resolvable, Resolve, SyncResolve}; +use std::future::{IntoFuture, Ready}; +use zenoh_core::{zread, Resolvable, Resolve, SyncResolve}; use zenoh_protocol::network::push::ext; use zenoh_protocol::network::Mapping; use zenoh_protocol::network::Push; @@ -57,12 +57,11 @@ pub struct PublicationBuilderDelete; /// use zenoh::publication::CongestionControl; /// use zenoh::sample::builder::{ValueBuilderTrait, QoSBuilderTrait}; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// session /// .put("key/expression", "payload") /// .encoding(Encoding::TEXT_PLAIN) /// .congestion_control(CongestionControl::Block) -/// .res() /// .await /// .unwrap(); /// # } @@ -225,18 +224,20 @@ impl SyncResolve for PublicationBuilder, PublicationBui } } -impl AsyncResolve for PublicationBuilder, PublicationBuilderPut> { - type Future = Ready; +impl IntoFuture for PublicationBuilder, PublicationBuilderPut> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } -impl AsyncResolve for PublicationBuilder, PublicationBuilderDelete> { - type Future = Ready; +impl IntoFuture for PublicationBuilder, PublicationBuilderDelete> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -287,9 +288,9 @@ impl std::fmt::Debug for PublisherRef<'_> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); -/// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); -/// publisher.put("value").res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); +/// let publisher = session.declare_publisher("key/expression").await.unwrap(); +/// publisher.put("value").await.unwrap(); /// # } /// ``` /// @@ -302,9 +303,9 @@ impl std::fmt::Debug for PublisherRef<'_> { /// use futures::StreamExt; /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); -/// let mut subscriber = session.declare_subscriber("key/expression").res().await.unwrap(); -/// let publisher = session.declare_publisher("another/key/expression").res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); +/// let mut subscriber = session.declare_subscriber("key/expression").await.unwrap(); +/// let publisher = session.declare_publisher("another/key/expression").await.unwrap(); /// subscriber.stream().map(Ok).forward(publisher).await.unwrap(); /// # } /// ``` @@ -329,9 +330,8 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let publisher = session.declare_publisher("key/expression") - /// .res() /// .await /// .unwrap(); /// let publisher_id = publisher.id(); @@ -385,9 +385,9 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap().into_arc(); - /// let matching_listener = publisher.matching_listener().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap().into_arc(); + /// let matching_listener = publisher.matching_listener().await.unwrap(); /// /// tokio::task::spawn(async move { /// while let Ok(matching_status) = matching_listener.recv_async().await { @@ -413,9 +413,9 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); - /// publisher.put("value").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); + /// publisher.put("value").await.unwrap(); /// # } /// ``` #[inline] @@ -445,9 +445,9 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); - /// publisher.delete().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); + /// publisher.delete().await.unwrap(); /// # } /// ``` pub fn delete(&self) -> PublisherDeleteBuilder<'_> { @@ -473,11 +473,10 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); /// let matching_subscribers: bool = publisher /// .matching_status() - /// .res() /// .await /// .unwrap() /// .matching_subscribers(); @@ -502,9 +501,9 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); - /// let matching_listener = publisher.matching_listener().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); + /// let matching_listener = publisher.matching_listener().await.unwrap(); /// while let Ok(matching_status) = matching_listener.recv_async().await { /// if matching_status.matching_subscribers() { /// println!("Publisher has matching subscribers."); @@ -530,9 +529,9 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); - /// publisher.undeclare().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); + /// publisher.undeclare().await.unwrap(); /// # } /// ``` pub fn undeclare(self) -> impl Resolve> + 'a { @@ -554,9 +553,9 @@ impl<'a> Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); -/// let publisher = session.declare_publisher("key/expression").res().await.unwrap().into_arc(); -/// let matching_listener = publisher.matching_listener().res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); +/// let publisher = session.declare_publisher("key/expression").await.unwrap().into_arc(); +/// let matching_listener = publisher.matching_listener().await.unwrap(); /// /// tokio::task::spawn(async move { /// while let Ok(matching_status) = matching_listener.recv_async().await { @@ -577,9 +576,9 @@ pub trait PublisherDeclarations { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap().into_arc(); - /// let matching_listener = publisher.matching_listener().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap().into_arc(); + /// let matching_listener = publisher.matching_listener().await.unwrap(); /// /// tokio::task::spawn(async move { /// while let Ok(matching_status) = matching_listener.recv_async().await { @@ -604,9 +603,9 @@ impl PublisherDeclarations for std::sync::Arc> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap().into_arc(); - /// let matching_listener = publisher.matching_listener().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap().into_arc(); + /// let matching_listener = publisher.matching_listener().await.unwrap(); /// /// tokio::task::spawn(async move { /// while let Ok(matching_status) = matching_listener.recv_async().await { @@ -642,9 +641,9 @@ impl<'a> Undeclarable<(), PublisherUndeclaration<'a>> for Publisher<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); -/// publisher.undeclare().res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let publisher = session.declare_publisher("key/expression").await.unwrap(); +/// publisher.undeclare().await.unwrap(); /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -669,10 +668,11 @@ impl SyncResolve for PublisherUndeclaration<'_> { } } -impl AsyncResolve for PublisherUndeclaration<'_> { - type Future = Ready; +impl IntoFuture for PublisherUndeclaration<'_> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -720,18 +720,20 @@ impl SyncResolve for PublicationBuilder<&Publisher<'_>, PublicationBuilderDelete } } -impl AsyncResolve for PublicationBuilder<&Publisher<'_>, PublicationBuilderPut> { - type Future = Ready; +impl IntoFuture for PublicationBuilder<&Publisher<'_>, PublicationBuilderPut> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } -impl AsyncResolve for PublicationBuilder<&Publisher<'_>, PublicationBuilderDelete> { - type Future = Ready; +impl IntoFuture for PublicationBuilder<&Publisher<'_>, PublicationBuilderDelete> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -788,11 +790,10 @@ impl<'a> Sink for Publisher<'a> { /// use zenoh::publication::CongestionControl; /// use zenoh::sample::builder::QoSBuilderTrait; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let publisher = session /// .declare_publisher("key/expression") /// .congestion_control(CongestionControl::Block) -/// .res() /// .await /// .unwrap(); /// # } @@ -931,10 +932,11 @@ impl<'a, 'b> SyncResolve for PublisherBuilder<'a, 'b> { } } -impl<'a, 'b> AsyncResolve for PublisherBuilder<'a, 'b> { - type Future = Ready; +impl<'a, 'b> IntoFuture for PublisherBuilder<'a, 'b> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -1135,9 +1137,9 @@ impl TryFrom for Priority { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); -/// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); -/// let matching_status = publisher.matching_status().res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); +/// let publisher = session.declare_publisher("key/expression").await.unwrap(); +/// let matching_status = publisher.matching_status().await.unwrap(); /// # } /// ``` #[zenoh_macros::unstable] @@ -1156,11 +1158,10 @@ impl MatchingStatus { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); /// let matching_subscribers: bool = publisher /// .matching_status() - /// .res() /// .await /// .unwrap() /// .matching_subscribers(); @@ -1189,8 +1190,8 @@ impl<'a> MatchingListenerBuilder<'a, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); /// let matching_listener = publisher /// .matching_listener() /// .callback(|matching_status| { @@ -1200,7 +1201,6 @@ impl<'a> MatchingListenerBuilder<'a, DefaultHandler> { /// println!("Publisher has NO MORE matching subscribers."); /// } /// }) - /// .res() /// .await /// .unwrap(); /// # } @@ -1230,12 +1230,11 @@ impl<'a> MatchingListenerBuilder<'a, DefaultHandler> { /// use zenoh::prelude::r#async::*; /// /// let mut n = 0; - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); /// let matching_listener = publisher /// .matching_listener() /// .callback_mut(move |_matching_status| { n += 1; }) - /// .res() /// .await /// .unwrap(); /// # } @@ -1260,12 +1259,11 @@ impl<'a> MatchingListenerBuilder<'a, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); /// let matching_listener = publisher /// .matching_listener() /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// while let Ok(matching_status) = matching_listener.recv_async().await { @@ -1324,15 +1322,15 @@ where } #[zenoh_macros::unstable] -impl<'a, Handler> AsyncResolve for MatchingListenerBuilder<'a, Handler> +impl<'a, Handler> IntoFuture for MatchingListenerBuilder<'a, Handler> where Handler: IntoHandler<'static, MatchingStatus> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - #[zenoh_macros::unstable] - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -1387,9 +1385,9 @@ impl<'a> Undeclarable<(), MatchingListenerUndeclaration<'a>> for MatchingListene /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); -/// let matching_listener = publisher.matching_listener().res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let publisher = session.declare_publisher("key/expression").await.unwrap(); +/// let matching_listener = publisher.matching_listener().await.unwrap(); /// while let Ok(matching_status) = matching_listener.recv_async().await { /// if matching_status.matching_subscribers() { /// println!("Publisher has matching subscribers."); @@ -1418,10 +1416,10 @@ impl<'a, Receiver> MatchingListener<'a, Receiver> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); - /// let matching_listener = publisher.matching_listener().res().await.unwrap(); - /// matching_listener.undeclare().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let publisher = session.declare_publisher("key/expression").await.unwrap(); + /// let matching_listener = publisher.matching_listener().await.unwrap(); + /// matching_listener.undeclare().await.unwrap(); /// # } /// ``` #[inline] @@ -1474,10 +1472,11 @@ impl SyncResolve for MatchingListenerUndeclaration<'_> { } #[zenoh_macros::unstable] -impl AsyncResolve for MatchingListenerUndeclaration<'_> { - type Future = Ready; +impl IntoFuture for MatchingListenerUndeclaration<'_> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } diff --git a/zenoh/src/query.rs b/zenoh/src/query.rs index becfad4922..c1572ec431 100644 --- a/zenoh/src/query.rs +++ b/zenoh/src/query.rs @@ -20,9 +20,9 @@ use crate::Session; #[cfg(feature = "unstable")] use crate::{payload::OptionPayload, sample::Attachment}; use std::collections::HashMap; -use std::future::Ready; +use std::future::{IntoFuture, Ready}; use std::time::Duration; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use zenoh_core::{Resolvable, SyncResolve}; use zenoh_result::ZResult; /// The [`Queryable`](crate::queryable::Queryable)s that should be target of a [`get`](Session::get). @@ -122,12 +122,11 @@ pub(crate) struct QueryState { /// use zenoh::prelude::r#async::*; /// use zenoh::query::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let replies = session /// .get("key/expression?value>1") /// .target(QueryTarget::All) /// .consolidation(ConsolidationMode::None) -/// .res() /// .await /// .unwrap(); /// while let Ok(reply) = replies.recv_async().await { @@ -227,11 +226,10 @@ impl<'a, 'b> GetBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let queryable = session /// .get("key/expression") /// .callback(|reply| {println!("Received {:?}", reply.result());}) - /// .res() /// .await /// .unwrap(); /// # } @@ -286,12 +284,11 @@ impl<'a, 'b> GetBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let mut n = 0; /// let queryable = session /// .get("key/expression") /// .callback_mut(move |reply| {n += 1;}) - /// .res() /// .await /// .unwrap(); /// # } @@ -315,11 +312,10 @@ impl<'a, 'b> GetBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let replies = session /// .get("key/expression") /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// while let Ok(reply) = replies.recv_async().await { @@ -472,14 +468,15 @@ where } } -impl AsyncResolve for GetBuilder<'_, '_, Handler> +impl IntoFuture for GetBuilder<'_, '_, Handler> where Handler: IntoHandler<'static, Reply> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } diff --git a/zenoh/src/queryable.rs b/zenoh/src/queryable.rs index 755e0364af..0c69ad7214 100644 --- a/zenoh/src/queryable.rs +++ b/zenoh/src/queryable.rs @@ -31,11 +31,11 @@ use crate::{ sample::{Attachment, SourceInfo}, }; use std::fmt; -use std::future::Ready; +use std::future::{IntoFuture, Ready}; use std::ops::{Deref, DerefMut}; use std::sync::Arc; use uhlc::Timestamp; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use zenoh_core::{Resolvable, SyncResolve}; use zenoh_protocol::{ core::{EntityId, WireExpr}, network::{response, Mapping, RequestId, Response, ResponseFinal}, @@ -265,10 +265,11 @@ impl SyncResolve for ReplySample<'_> { } } -impl AsyncResolve for ReplySample<'_> { - type Future = Ready; +impl IntoFuture for ReplySample<'_> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -470,18 +471,20 @@ impl Query { } } -impl AsyncResolve for ReplyBuilder<'_, '_, ReplyBuilderPut> { - type Future = Ready; +impl IntoFuture for ReplyBuilder<'_, '_, ReplyBuilderPut> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } -impl AsyncResolve for ReplyBuilder<'_, '_, ReplyBuilderDelete> { - type Future = Ready; +impl IntoFuture for ReplyBuilder<'_, '_, ReplyBuilderDelete> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -545,10 +548,11 @@ impl SyncResolve for ReplyErrBuilder<'_> { } } -impl<'a> AsyncResolve for ReplyErrBuilder<'a> { - type Future = Ready; +impl<'a> IntoFuture for ReplyErrBuilder<'a> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -587,12 +591,11 @@ impl fmt::Debug for QueryableState { /// use futures::prelude::*; /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let queryable = session.declare_queryable("key/expression").res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let queryable = session.declare_queryable("key/expression").await.unwrap(); /// while let Ok(query) = queryable.recv_async().await { /// println!(">> Handling query '{}'", query.selector()); /// query.reply(KeyExpr::try_from("key/expression").unwrap(), "value") -/// .res() /// .await /// .unwrap(); /// } @@ -619,9 +622,9 @@ impl<'a> Undeclarable<(), QueryableUndeclaration<'a>> for CallbackQueryable<'a> /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let queryable = session.declare_queryable("key/expression").res().await.unwrap(); -/// queryable.undeclare().res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let queryable = session.declare_queryable("key/expression").await.unwrap(); +/// queryable.undeclare().await.unwrap(); /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -642,10 +645,11 @@ impl SyncResolve for QueryableUndeclaration<'_> { } } -impl<'a> AsyncResolve for QueryableUndeclaration<'a> { - type Future = Ready; +impl<'a> IntoFuture for QueryableUndeclaration<'a> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -667,8 +671,8 @@ impl Drop for CallbackQueryable<'_> { /// use zenoh::prelude::r#async::*; /// use zenoh::queryable; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); -/// let queryable = session.declare_queryable("key/expression").res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); +/// let queryable = session.declare_queryable("key/expression").await.unwrap(); /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -690,11 +694,10 @@ impl<'a, 'b> QueryableBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let queryable = session /// .declare_queryable("key/expression") /// .callback(|query| {println!(">> Handling query '{}'", query.selector());}) - /// .res() /// .await /// .unwrap(); /// # } @@ -731,12 +734,11 @@ impl<'a, 'b> QueryableBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let mut n = 0; /// let queryable = session /// .declare_queryable("key/expression") /// .callback_mut(move |query| {n += 1;}) - /// .res() /// .await /// .unwrap(); /// # } @@ -760,11 +762,10 @@ impl<'a, 'b> QueryableBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let queryable = session /// .declare_queryable("key/expression") /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// while let Ok(query) = queryable.recv_async().await { @@ -826,17 +827,15 @@ impl<'a, 'b, Handler> QueryableBuilder<'a, 'b, Handler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let queryable = session /// .declare_queryable("key/expression") /// .with(flume::bounded(32)) -/// .res() /// .await /// .unwrap(); /// while let Ok(query) = queryable.recv_async().await { /// println!(">> Handling query '{}'", query.selector()); /// query.reply(KeyExpr::try_from("key/expression").unwrap(), "value") -/// .res() /// .await /// .unwrap(); /// } @@ -858,9 +857,8 @@ impl<'a, Handler> Queryable<'a, Handler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let queryable = session.declare_queryable("key/expression") - /// .res() /// .await /// .unwrap(); /// let queryable_id = queryable.id(); @@ -948,14 +946,15 @@ where } } -impl<'a, Handler> AsyncResolve for QueryableBuilder<'a, '_, Handler> +impl<'a, Handler> IntoFuture for QueryableBuilder<'a, '_, Handler> where Handler: IntoHandler<'static, Query> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } diff --git a/zenoh/src/scouting.rs b/zenoh/src/scouting.rs index c811319d39..a56b1d5db0 100644 --- a/zenoh/src/scouting.rs +++ b/zenoh/src/scouting.rs @@ -14,10 +14,11 @@ use crate::handlers::{locked, Callback, DefaultHandler}; use crate::net::runtime::{orchestrator::Loop, Runtime}; +use std::future::IntoFuture; use std::time::Duration; use std::{fmt, future::Ready, net::SocketAddr, ops::Deref}; use tokio::net::UdpSocket; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use zenoh_core::{Resolvable, SyncResolve}; use zenoh_protocol::core::WhatAmIMatcher; use zenoh_result::ZResult; use zenoh_task::TerminatableTask; @@ -38,7 +39,6 @@ pub use zenoh_protocol::scouting::Hello; /// use zenoh::scouting::WhatAmI; /// /// let receiver = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) -/// .res() /// .await /// .unwrap(); /// while let Ok(hello) = receiver.recv_async().await { @@ -66,7 +66,6 @@ impl ScoutBuilder { /// /// let scout = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) /// .callback(|hello| { println!("{}", hello); }) - /// .res() /// .await /// .unwrap(); /// # } @@ -103,7 +102,6 @@ impl ScoutBuilder { /// let mut n = 0; /// let scout = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) /// .callback_mut(move |_hello| { n += 1; }) - /// .res() /// .await /// .unwrap(); /// # } @@ -130,7 +128,6 @@ impl ScoutBuilder { /// /// let receiver = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// while let Ok(hello) = receiver.recv_async().await { @@ -175,14 +172,15 @@ where } } -impl AsyncResolve for ScoutBuilder +impl IntoFuture for ScoutBuilder where Handler: crate::prelude::IntoHandler<'static, Hello> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -198,7 +196,6 @@ where /// /// let scout = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) /// .callback(|hello| { println!("{}", hello); }) -/// .res() /// .await /// .unwrap(); /// # } @@ -220,7 +217,6 @@ impl ScoutInner { /// /// let scout = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) /// .callback(|hello| { println!("{}", hello); }) - /// .res() /// .await /// .unwrap(); /// scout.stop(); @@ -257,7 +253,6 @@ impl fmt::Debug for ScoutInner { /// /// let receiver = zenoh::scout(WhatAmI::Peer | WhatAmI::Router, config::default()) /// .with(flume::bounded(32)) -/// .res() /// .await /// .unwrap(); /// while let Ok(hello) = receiver.recv_async().await { @@ -292,7 +287,6 @@ impl Scout { /// /// let scout = zenoh::scout(WhatAmI::Router, config::default()) /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// let _router = scout.recv_async().await; diff --git a/zenoh/src/session.rs b/zenoh/src/session.rs index 6f047fda5d..a0d671a079 100644 --- a/zenoh/src/session.rs +++ b/zenoh/src/session.rs @@ -83,7 +83,6 @@ use zenoh_protocol::{ }; use zenoh_result::ZResult; use zenoh_task::TaskController; -use zenoh_util::core::AsyncResolve; zconfigurable! { pub(crate) static ref API_DATA_RECEPTION_CHANNEL_SIZE: usize = 256; @@ -406,7 +405,7 @@ impl Session { runtime: Runtime, aggregated_subscribers: Vec, aggregated_publishers: Vec, - ) -> impl Resolve { + ) -> impl Resolve + Send { ResolveClosure::new(move || { let router = runtime.router(); let state = Arc::new(RwLock::new(SessionState::new( @@ -450,9 +449,8 @@ impl Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let subscriber = session.declare_subscriber("key/expression") - /// .res() /// .await /// .unwrap(); /// tokio::task::spawn(async move { @@ -485,8 +483,8 @@ impl Session { /// use zenoh::prelude::r#async::*; /// use zenoh::Session; /// - /// let session = Session::leak(zenoh::open(config::peer()).res().await.unwrap()); - /// let subscriber = session.declare_subscriber("key/expression").res().await.unwrap(); + /// let session = Session::leak(zenoh::open(config::peer()).await.unwrap()); + /// let subscriber = session.declare_subscriber("key/expression").await.unwrap(); /// tokio::task::spawn(async move { /// while let Ok(sample) = subscriber.recv_async().await { /// println!("Received: {:?}", sample); @@ -519,8 +517,8 @@ impl Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// session.close().res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// session.close().await.unwrap(); /// # } /// ``` pub fn close(mut self) -> impl Resolve> { @@ -562,7 +560,7 @@ impl Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let peers = session.config().get("connect/endpoints").unwrap(); /// # } /// ``` @@ -573,7 +571,7 @@ impl Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let _ = session.config().insert_json5("connect/endpoints", r#"["tcp/127.0.0.1/7447"]"#); /// # } /// ``` @@ -634,8 +632,8 @@ impl Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let key_expr = session.declare_keyexpr("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let key_expr = session.declare_keyexpr("key/expression").await.unwrap(); /// # } /// ``` pub fn declare_keyexpr<'a, 'b: 'a, TryIntoKeyExpr>( @@ -697,11 +695,10 @@ impl Session { /// use zenoh::prelude::r#async::*; /// use zenoh::prelude::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// session /// .put("key/expression", "payload") /// .encoding(Encoding::TEXT_PLAIN) - /// .res() /// .await /// .unwrap(); /// # } @@ -743,8 +740,8 @@ impl Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// session.delete("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// session.delete("key/expression").await.unwrap(); /// # } /// ``` #[inline] @@ -781,8 +778,8 @@ impl Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); - /// let replies = session.get("key/expression").res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); + /// let replies = session.get("key/expression").await.unwrap(); /// while let Ok(reply) = replies.recv_async().await { /// println!(">> Received {:?}", reply.result()); /// } @@ -846,7 +843,6 @@ impl Session { aggregated_subscribers, aggregated_publishers, ) - .res_async() .await; session.owns_runtime = true; match runtime.start().await { @@ -1838,9 +1834,8 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let subscriber = session.declare_subscriber("key/expression") - /// .res() /// .await /// .unwrap(); /// tokio::task::spawn(async move { @@ -1880,9 +1875,8 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let queryable = session.declare_queryable("key/expression") - /// .res() /// .await /// .unwrap(); /// tokio::task::spawn(async move { @@ -1890,7 +1884,7 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc { /// query.reply( /// KeyExpr::try_from("key/expression").unwrap(), /// "value", - /// ).res().await.unwrap(); + /// ).await.unwrap(); /// } /// }).await; /// # } @@ -1924,12 +1918,11 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let publisher = session.declare_publisher("key/expression") - /// .res() /// .await /// .unwrap(); - /// publisher.put("value").res().await.unwrap(); + /// publisher.put("value").await.unwrap(); /// # } /// ``` fn declare_publisher<'b, TryIntoKeyExpr>( @@ -1958,11 +1951,10 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") - /// .res() /// .await /// .unwrap(); /// # } @@ -2446,9 +2438,8 @@ impl fmt::Debug for Session { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); +/// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let subscriber = session.declare_subscriber("key/expression") -/// .res() /// .await /// .unwrap(); /// tokio::task::spawn(async move { @@ -2471,9 +2462,8 @@ pub trait SessionDeclarations<'s, 'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let subscriber = session.declare_subscriber("key/expression") - /// .res() /// .await /// .unwrap(); /// tokio::task::spawn(async move { @@ -2504,9 +2494,8 @@ pub trait SessionDeclarations<'s, 'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let queryable = session.declare_queryable("key/expression") - /// .res() /// .await /// .unwrap(); /// tokio::task::spawn(async move { @@ -2514,7 +2503,7 @@ pub trait SessionDeclarations<'s, 'a> { /// query.reply( /// KeyExpr::try_from("key/expression").unwrap(), /// "value", - /// ).res().await.unwrap(); + /// ).await.unwrap(); /// } /// }).await; /// # } @@ -2539,12 +2528,11 @@ pub trait SessionDeclarations<'s, 'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let publisher = session.declare_publisher("key/expression") - /// .res() /// .await /// .unwrap(); - /// publisher.put("value").res().await.unwrap(); + /// publisher.put("value").await.unwrap(); /// # } /// ``` fn declare_publisher<'b, TryIntoKeyExpr>( @@ -2563,11 +2551,10 @@ pub trait SessionDeclarations<'s, 'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let session = zenoh::open(config::peer()).await.unwrap().into_arc(); /// let liveliness = session /// .liveliness() /// .declare_token("key/expression") - /// .res() /// .await /// .unwrap(); /// # } @@ -2582,7 +2569,7 @@ pub trait SessionDeclarations<'s, 'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let info = session.info(); /// # } /// ``` diff --git a/zenoh/src/subscriber.rs b/zenoh/src/subscriber.rs index ded2a1acdc..0dfdb32b12 100644 --- a/zenoh/src/subscriber.rs +++ b/zenoh/src/subscriber.rs @@ -21,10 +21,10 @@ use crate::Id; use crate::Undeclarable; use crate::{Result as ZResult, SessionRef}; use std::fmt; -use std::future::Ready; +use std::future::{IntoFuture, Ready}; use std::ops::{Deref, DerefMut}; use std::sync::Arc; -use zenoh_core::{AsyncResolve, Resolvable, SyncResolve}; +use zenoh_core::{Resolvable, SyncResolve}; #[cfg(feature = "unstable")] use zenoh_protocol::core::EntityGlobalId; use zenoh_protocol::network::declare::subscriber::ext::SubscriberInfo; @@ -65,11 +65,10 @@ impl fmt::Debug for SubscriberState { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr(), sample.payload()) }) -/// .res() /// .await /// .unwrap(); /// # } @@ -93,15 +92,14 @@ impl<'a> SubscriberInner<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// # fn data_handler(_sample: Sample) { }; /// let subscriber = session /// .declare_subscriber("key/expression") /// .callback(data_handler) - /// .res() /// .await /// .unwrap(); - /// subscriber.undeclare().res().await.unwrap(); + /// subscriber.undeclare().await.unwrap(); /// # } /// ``` #[inline] @@ -124,13 +122,12 @@ impl<'a> Undeclarable<(), SubscriberUndeclaration<'a>> for SubscriberInner<'a> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") -/// .res() /// .await /// .unwrap(); -/// subscriber.undeclare().res().await.unwrap(); +/// subscriber.undeclare().await.unwrap(); /// # } /// ``` #[must_use = "Resolvables do nothing unless you resolve them using the `res` method from either `SyncResolve` or `AsyncResolve`"] @@ -151,10 +148,11 @@ impl SyncResolve for SubscriberUndeclaration<'_> { } } -impl AsyncResolve for SubscriberUndeclaration<'_> { - type Future = Ready; +impl IntoFuture for SubscriberUndeclaration<'_> { + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -175,11 +173,10 @@ impl Drop for SubscriberInner<'_> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .best_effort() -/// .res() /// .await /// .unwrap(); /// # } @@ -222,11 +219,10 @@ impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr(), sample.payload()); }) - /// .res() /// .await /// .unwrap(); /// # } @@ -265,12 +261,11 @@ impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let mut n = 0; /// let subscriber = session /// .declare_subscriber("key/expression") /// .callback_mut(move |_sample| { n += 1; }) - /// .res() /// .await /// .unwrap(); /// # } @@ -294,11 +289,10 @@ impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .with(flume::bounded(32)) - /// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -399,14 +393,15 @@ where } } -impl<'a, Handler> AsyncResolve for SubscriberBuilder<'a, '_, Handler> +impl<'a, Handler> IntoFuture for SubscriberBuilder<'a, '_, Handler> where Handler: IntoHandler<'static, Sample> + Send, Handler::Handler: Send, { - type Future = Ready; + type Output = ::To; + type IntoFuture = Ready<::To>; - fn res_async(self) -> Self::Future { + fn into_future(self) -> Self::IntoFuture { std::future::ready(self.res_sync()) } } @@ -426,11 +421,10 @@ where /// # async fn main() { /// use zenoh::prelude::r#async::*; /// -/// let session = zenoh::open(config::peer()).res().await.unwrap(); +/// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session /// .declare_subscriber("key/expression") /// .with(flume::bounded(32)) -/// .res() /// .await /// .unwrap(); /// while let Ok(sample) = subscriber.recv_async().await { @@ -454,9 +448,8 @@ impl<'a, Handler> Subscriber<'a, Handler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session.declare_subscriber("key/expression") - /// .res() /// .await /// .unwrap(); /// let subscriber_id = subscriber.id(); @@ -500,12 +493,11 @@ impl<'a, Handler> Subscriber<'a, Handler> { /// # async fn main() { /// use zenoh::prelude::r#async::*; /// - /// let session = zenoh::open(config::peer()).res().await.unwrap(); + /// let session = zenoh::open(config::peer()).await.unwrap(); /// let subscriber = session.declare_subscriber("key/expression") - /// .res() /// .await /// .unwrap(); - /// subscriber.undeclare().res().await.unwrap(); + /// subscriber.undeclare().await.unwrap(); /// # } /// ``` #[inline] diff --git a/zenoh/tests/acl.rs b/zenoh/tests/acl.rs index c099fa021e..366b73c547 100644 --- a/zenoh/tests/acl.rs +++ b/zenoh/tests/acl.rs @@ -46,22 +46,22 @@ mod test { async fn close_router_session(s: Session) { println!("Closing router session"); - ztimeout!(s.close().res_async()).unwrap(); + ztimeout!(s.close()).unwrap(); } async fn get_client_sessions() -> (Session, Session) { println!("Opening client sessions"); let config = config::client(["tcp/127.0.0.1:7447".parse::().unwrap()]); - let s01 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s01 = ztimeout!(zenoh::open(config)).unwrap(); let config = config::client(["tcp/127.0.0.1:7447".parse::().unwrap()]); - let s02 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s02 = ztimeout!(zenoh::open(config)).unwrap(); (s01, s02) } async fn close_sessions(s01: Session, s02: Session) { println!("Closing client sessions"); - ztimeout!(s01.close().res_async()).unwrap(); - ztimeout!(s02.close().res_async()).unwrap(); + ztimeout!(s01.close()).unwrap(); + ztimeout!(s02.close()).unwrap(); } async fn test_pub_sub_deny() { @@ -82,15 +82,11 @@ mod test { .unwrap(); println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (sub_session, pub_session) = get_client_sessions().await; { - let publisher = pub_session - .declare_publisher(KEY_EXPR) - .res_async() - .await - .unwrap(); + let publisher = pub_session.declare_publisher(KEY_EXPR).await.unwrap(); let received_value = Arc::new(Mutex::new(String::new())); let temp_recv_value = received_value.clone(); let subscriber = sub_session @@ -99,15 +95,14 @@ mod test { let mut temp_value = zlock!(temp_recv_value); *temp_value = sample.payload().deserialize::().unwrap(); }) - .res_async() .await .unwrap(); tokio::time::sleep(SLEEP).await; - publisher.put(VALUE).res_async().await.unwrap(); + publisher.put(VALUE).await.unwrap(); tokio::time::sleep(SLEEP).await; assert_ne!(*zlock!(received_value), VALUE); - ztimeout!(subscriber.undeclare().res_async()).unwrap(); + ztimeout!(subscriber.undeclare()).unwrap(); } close_sessions(sub_session, pub_session).await; close_router_session(session).await; @@ -132,28 +127,28 @@ mod test { .unwrap(); println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (sub_session, pub_session) = get_client_sessions().await; { - let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR).res_async()).unwrap(); + let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR)).unwrap(); let received_value = Arc::new(Mutex::new(String::new())); let temp_recv_value = received_value.clone(); - let subscriber = ztimeout!(sub_session - .declare_subscriber(KEY_EXPR) - .callback(move |sample| { - let mut temp_value = zlock!(temp_recv_value); - *temp_value = sample.payload().deserialize::().unwrap(); - }) - .res_async()) - .unwrap(); + let subscriber = + ztimeout!(sub_session + .declare_subscriber(KEY_EXPR) + .callback(move |sample| { + let mut temp_value = zlock!(temp_recv_value); + *temp_value = sample.payload().deserialize::().unwrap(); + })) + .unwrap(); tokio::time::sleep(SLEEP).await; - ztimeout!(publisher.put(VALUE).res_async()).unwrap(); + ztimeout!(publisher.put(VALUE)).unwrap(); tokio::time::sleep(SLEEP).await; assert_eq!(*zlock!(received_value), VALUE); - ztimeout!(subscriber.undeclare().res_async()).unwrap(); + ztimeout!(subscriber.undeclare()).unwrap(); } close_sessions(sub_session, pub_session).await; @@ -193,28 +188,28 @@ mod test { .unwrap(); println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (sub_session, pub_session) = get_client_sessions().await; { - let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR).res_async()).unwrap(); + let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR)).unwrap(); let received_value = Arc::new(Mutex::new(String::new())); let temp_recv_value = received_value.clone(); - let subscriber = ztimeout!(sub_session - .declare_subscriber(KEY_EXPR) - .callback(move |sample| { - let mut temp_value = zlock!(temp_recv_value); - *temp_value = sample.payload().deserialize::().unwrap(); - }) - .res_async()) - .unwrap(); + let subscriber = + ztimeout!(sub_session + .declare_subscriber(KEY_EXPR) + .callback(move |sample| { + let mut temp_value = zlock!(temp_recv_value); + *temp_value = sample.payload().deserialize::().unwrap(); + })) + .unwrap(); tokio::time::sleep(SLEEP).await; - ztimeout!(publisher.put(VALUE).res_async()).unwrap(); + ztimeout!(publisher.put(VALUE)).unwrap(); tokio::time::sleep(SLEEP).await; assert_ne!(*zlock!(received_value), VALUE); - ztimeout!(subscriber.undeclare().res_async()).unwrap(); + ztimeout!(subscriber.undeclare()).unwrap(); } close_sessions(sub_session, pub_session).await; close_router_session(session).await; @@ -253,28 +248,28 @@ mod test { .unwrap(); println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (sub_session, pub_session) = get_client_sessions().await; { - let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR).res_async()).unwrap(); + let publisher = ztimeout!(pub_session.declare_publisher(KEY_EXPR)).unwrap(); let received_value = Arc::new(Mutex::new(String::new())); let temp_recv_value = received_value.clone(); - let subscriber = ztimeout!(sub_session - .declare_subscriber(KEY_EXPR) - .callback(move |sample| { - let mut temp_value = zlock!(temp_recv_value); - *temp_value = sample.payload().deserialize::().unwrap(); - }) - .res_async()) - .unwrap(); + let subscriber = + ztimeout!(sub_session + .declare_subscriber(KEY_EXPR) + .callback(move |sample| { + let mut temp_value = zlock!(temp_recv_value); + *temp_value = sample.payload().deserialize::().unwrap(); + })) + .unwrap(); tokio::time::sleep(SLEEP).await; - ztimeout!(publisher.put(VALUE).res_async()).unwrap(); + ztimeout!(publisher.put(VALUE)).unwrap(); tokio::time::sleep(SLEEP).await; assert_eq!(*zlock!(received_value), VALUE); - ztimeout!(subscriber.undeclare().res_async()).unwrap(); + ztimeout!(subscriber.undeclare()).unwrap(); } close_sessions(sub_session, pub_session).await; close_router_session(session).await; @@ -298,7 +293,7 @@ mod test { .unwrap(); println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (get_session, qbl_session) = get_client_sessions().await; { @@ -309,15 +304,14 @@ mod test { .callback(move |sample| { tokio::task::block_in_place(move || { Handle::current().block_on(async move { - ztimeout!(sample.reply(KEY_EXPR, VALUE).res_async()).unwrap() + ztimeout!(sample.reply(KEY_EXPR, VALUE)).unwrap() }); }); - }) - .res_async()) + })) .unwrap(); tokio::time::sleep(SLEEP).await; - let recv_reply = ztimeout!(get_session.get(KEY_EXPR).res_async()).unwrap(); + let recv_reply = ztimeout!(get_session.get(KEY_EXPR)).unwrap(); while let Ok(reply) = ztimeout!(recv_reply.recv_async()) { match reply.result() { Ok(sample) => { @@ -329,7 +323,7 @@ mod test { } tokio::time::sleep(SLEEP).await; assert_ne!(received_value, VALUE); - ztimeout!(qbl.undeclare().res_async()).unwrap(); + ztimeout!(qbl.undeclare()).unwrap(); } close_sessions(get_session, qbl_session).await; close_router_session(session).await; @@ -353,7 +347,7 @@ mod test { .unwrap(); println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (get_session, qbl_session) = get_client_sessions().await; { @@ -364,15 +358,14 @@ mod test { .callback(move |sample| { tokio::task::block_in_place(move || { Handle::current().block_on(async move { - ztimeout!(sample.reply(KEY_EXPR, VALUE).res_async()).unwrap() + ztimeout!(sample.reply(KEY_EXPR, VALUE)).unwrap() }); }); - }) - .res_async()) + })) .unwrap(); tokio::time::sleep(SLEEP).await; - let recv_reply = ztimeout!(get_session.get(KEY_EXPR).res_async()).unwrap(); + let recv_reply = ztimeout!(get_session.get(KEY_EXPR)).unwrap(); while let Ok(reply) = ztimeout!(recv_reply.recv_async()) { match reply.result() { Ok(sample) => { @@ -384,7 +377,7 @@ mod test { } tokio::time::sleep(SLEEP).await; assert_eq!(received_value, VALUE); - ztimeout!(qbl.undeclare().res_async()).unwrap(); + ztimeout!(qbl.undeclare()).unwrap(); } close_sessions(get_session, qbl_session).await; close_router_session(session).await; @@ -423,7 +416,7 @@ mod test { println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (get_session, qbl_session) = get_client_sessions().await; { @@ -434,15 +427,14 @@ mod test { .callback(move |sample| { tokio::task::block_in_place(move || { Handle::current().block_on(async move { - ztimeout!(sample.reply(KEY_EXPR, VALUE).res_async()).unwrap() + ztimeout!(sample.reply(KEY_EXPR, VALUE)).unwrap() }); }); - }) - .res_async()) + })) .unwrap(); tokio::time::sleep(SLEEP).await; - let recv_reply = ztimeout!(get_session.get(KEY_EXPR).res_async()).unwrap(); + let recv_reply = ztimeout!(get_session.get(KEY_EXPR)).unwrap(); while let Ok(reply) = ztimeout!(recv_reply.recv_async()) { match reply.result() { Ok(sample) => { @@ -454,7 +446,7 @@ mod test { } tokio::time::sleep(SLEEP).await; assert_eq!(received_value, VALUE); - ztimeout!(qbl.undeclare().res_async()).unwrap(); + ztimeout!(qbl.undeclare()).unwrap(); } close_sessions(get_session, qbl_session).await; close_router_session(session).await; @@ -492,7 +484,7 @@ mod test { .unwrap(); println!("Opening router session"); - let session = ztimeout!(zenoh::open(config_router).res_async()).unwrap(); + let session = ztimeout!(zenoh::open(config_router)).unwrap(); let (get_session, qbl_session) = get_client_sessions().await; { @@ -503,15 +495,14 @@ mod test { .callback(move |sample| { tokio::task::block_in_place(move || { Handle::current().block_on(async move { - ztimeout!(sample.reply(KEY_EXPR, VALUE).res_async()).unwrap() + ztimeout!(sample.reply(KEY_EXPR, VALUE)).unwrap() }); }); - }) - .res_async()) + })) .unwrap(); tokio::time::sleep(SLEEP).await; - let recv_reply = ztimeout!(get_session.get(KEY_EXPR).res_async()).unwrap(); + let recv_reply = ztimeout!(get_session.get(KEY_EXPR)).unwrap(); while let Ok(reply) = ztimeout!(recv_reply.recv_async()) { match reply.result() { Ok(sample) => { @@ -523,7 +514,7 @@ mod test { } tokio::time::sleep(SLEEP).await; assert_ne!(received_value, VALUE); - ztimeout!(qbl.undeclare().res_async()).unwrap(); + ztimeout!(qbl.undeclare()).unwrap(); } close_sessions(get_session, qbl_session).await; close_router_session(session).await; diff --git a/zenoh/tests/events.rs b/zenoh/tests/events.rs index 9c807bd121..c9091c7466 100644 --- a/zenoh/tests/events.rs +++ b/zenoh/tests/events.rs @@ -30,12 +30,12 @@ async fn open_session(listen: &[&str], connect: &[&str]) -> Session { .collect::>(); config.scouting.multicast.set_enabled(Some(false)).unwrap(); println!("[ ][01a] Opening session"); - ztimeout!(zenoh::open(config).res_async()).unwrap() + ztimeout!(zenoh::open(config)).unwrap() } async fn close_session(session: Session) { println!("[ ][01d] Closing session"); - ztimeout!(session.close().res_async()).unwrap(); + ztimeout!(session.close()).unwrap(); } #[tokio::test(flavor = "multi_thread", worker_threads = 4)] @@ -44,12 +44,10 @@ async fn zenoh_events() { let zid = session.zid(); let sub1 = session .declare_subscriber(format!("@/session/{zid}/transport/unicast/*")) - .res() .await .unwrap(); let sub2 = session .declare_subscriber(format!("@/session/{zid}/transport/unicast/*/link/*")) - .res() .await .unwrap(); @@ -68,23 +66,21 @@ async fn zenoh_events() { assert!(key_expr.starts_with(&format!("@/session/{zid}/transport/unicast/{zid2}/link/"))); assert!(sample.as_ref().unwrap().kind() == SampleKind::Put); - let replies: Vec = ztimeout!(session - .get(format!("@/session/{zid}/transport/unicast/*")) - .res_async()) - .unwrap() - .into_iter() - .collect(); + let replies: Vec = + ztimeout!(session.get(format!("@/session/{zid}/transport/unicast/*"))) + .unwrap() + .into_iter() + .collect(); assert!(replies.len() == 1); assert!(replies[0].result().is_ok()); let key_expr = replies[0].result().unwrap().key_expr().as_str(); assert!(key_expr.eq(&format!("@/session/{zid}/transport/unicast/{zid2}"))); - let replies: Vec = ztimeout!(session - .get(format!("@/session/{zid}/transport/unicast/*/link/*")) - .res_async()) - .unwrap() - .into_iter() - .collect(); + let replies: Vec = + ztimeout!(session.get(format!("@/session/{zid}/transport/unicast/*/link/*"))) + .unwrap() + .into_iter() + .collect(); assert!(replies.len() == 1); assert!(replies[0].result().is_ok()); let key_expr = replies[0].result().unwrap().key_expr().as_str(); @@ -104,7 +100,7 @@ async fn zenoh_events() { assert!(key_expr.starts_with(&format!("@/session/{zid}/transport/unicast/{zid2}/link/"))); assert!(sample.as_ref().unwrap().kind() == SampleKind::Delete); - sub2.undeclare().res().await.unwrap(); - sub1.undeclare().res().await.unwrap(); + sub2.undeclare().await.unwrap(); + sub1.undeclare().await.unwrap(); close_session(session).await; } diff --git a/zenoh/tests/liveliness.rs b/zenoh/tests/liveliness.rs index fe6ac99571..f518ed9303 100644 --- a/zenoh/tests/liveliness.rs +++ b/zenoh/tests/liveliness.rs @@ -26,33 +26,24 @@ async fn zenoh_liveliness() { .set_endpoints(vec!["tcp/localhost:47447".parse().unwrap()]) .unwrap(); c1.scouting.multicast.set_enabled(Some(false)).unwrap(); - let session1 = ztimeout!(zenoh::open(c1).res_async()).unwrap(); + let session1 = ztimeout!(zenoh::open(c1)).unwrap(); let mut c2 = config::peer(); c2.connect .set_endpoints(vec!["tcp/localhost:47447".parse().unwrap()]) .unwrap(); c2.scouting.multicast.set_enabled(Some(false)).unwrap(); - let session2 = ztimeout!(zenoh::open(c2).res_async()).unwrap(); + let session2 = ztimeout!(zenoh::open(c2)).unwrap(); let sub = ztimeout!(session2 .liveliness() - .declare_subscriber("zenoh_liveliness_test") - .res_async()) + .declare_subscriber("zenoh_liveliness_test")) .unwrap(); - let token = ztimeout!(session1 - .liveliness() - .declare_token("zenoh_liveliness_test") - .res_async()) - .unwrap(); + let token = ztimeout!(session1.liveliness().declare_token("zenoh_liveliness_test")).unwrap(); tokio::time::sleep(SLEEP).await; - let replies = ztimeout!(session2 - .liveliness() - .get("zenoh_liveliness_test") - .res_async()) - .unwrap(); + let replies = ztimeout!(session2.liveliness().get("zenoh_liveliness_test")).unwrap(); let sample: Sample = ztimeout!(replies.recv_async()) .unwrap() .into_result() @@ -70,11 +61,7 @@ async fn zenoh_liveliness() { tokio::time::sleep(SLEEP).await; - let replies = ztimeout!(session2 - .liveliness() - .get("zenoh_liveliness_test") - .res_async()) - .unwrap(); + let replies = ztimeout!(session2.liveliness().get("zenoh_liveliness_test")).unwrap(); assert!(ztimeout!(replies.recv_async()).is_err()); assert!(replies.try_recv().is_err()); diff --git a/zenoh/tests/matching.rs b/zenoh/tests/matching.rs index e56036f5de..94689e1bef 100644 --- a/zenoh/tests/matching.rs +++ b/zenoh/tests/matching.rs @@ -33,8 +33,8 @@ async fn create_session_pair(locator: &str) -> (Session, Session) { }; let config2 = zenoh::config::client([Locator::from_str(locator).unwrap()]); - let session1 = ztimeout!(zenoh::open(config1).res_async()).unwrap(); - let session2 = ztimeout!(zenoh::open(config2).res_async()).unwrap(); + let session1 = ztimeout!(zenoh::open(config1)).unwrap(); + let session2 = ztimeout!(zenoh::open(config2)).unwrap(); (session1, session2) } @@ -47,54 +47,47 @@ async fn zenoh_matching_status_any() -> Result<()> { let publisher1 = ztimeout!(session1 .declare_publisher("zenoh_matching_status_any_test") - .allowed_destination(Locality::Any) - .res_async()) + .allowed_destination(Locality::Any)) .unwrap(); - let matching_listener = ztimeout!(publisher1.matching_listener().res_async()).unwrap(); + let matching_listener = ztimeout!(publisher1.matching_listener()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.err() == Some(RecvTimeoutError::Timeout)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - let sub = ztimeout!(session1 - .declare_subscriber("zenoh_matching_status_any_test") - .res_async()) - .unwrap(); + let sub = ztimeout!(session1.declare_subscriber("zenoh_matching_status_any_test")).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(matching_status.matching_subscribers()); - ztimeout!(sub.undeclare().res_async()).unwrap(); + ztimeout!(sub.undeclare()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - let sub = ztimeout!(session2 - .declare_subscriber("zenoh_matching_status_any_test") - .res_async()) - .unwrap(); + let sub = ztimeout!(session2.declare_subscriber("zenoh_matching_status_any_test")).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(matching_status.matching_subscribers()); - ztimeout!(sub.undeclare().res_async()).unwrap(); + ztimeout!(sub.undeclare()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); Ok(()) } @@ -104,60 +97,53 @@ async fn zenoh_matching_status_any() -> Result<()> { async fn zenoh_matching_status_remote() -> Result<()> { use flume::RecvTimeoutError; - let session1 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap(); + let session1 = ztimeout!(zenoh::open(config::peer())).unwrap(); - let session2 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap(); + let session2 = ztimeout!(zenoh::open(config::peer())).unwrap(); let publisher1 = ztimeout!(session1 .declare_publisher("zenoh_matching_status_remote_test") - .allowed_destination(Locality::Remote) - .res_async()) + .allowed_destination(Locality::Remote)) .unwrap(); - let matching_listener = ztimeout!(publisher1.matching_listener().res_async()).unwrap(); + let matching_listener = ztimeout!(publisher1.matching_listener()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.err() == Some(RecvTimeoutError::Timeout)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - let sub = ztimeout!(session1 - .declare_subscriber("zenoh_matching_status_remote_test") - .res_async()) - .unwrap(); + let sub = ztimeout!(session1.declare_subscriber("zenoh_matching_status_remote_test")).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.err() == Some(RecvTimeoutError::Timeout)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - ztimeout!(sub.undeclare().res_async()).unwrap(); + ztimeout!(sub.undeclare()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.err() == Some(RecvTimeoutError::Timeout)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - let sub = ztimeout!(session2 - .declare_subscriber("zenoh_matching_status_remote_test") - .res_async()) - .unwrap(); + let sub = ztimeout!(session2.declare_subscriber("zenoh_matching_status_remote_test")).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(matching_status.matching_subscribers()); - ztimeout!(sub.undeclare().res_async()).unwrap(); + ztimeout!(sub.undeclare()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); Ok(()) @@ -168,60 +154,53 @@ async fn zenoh_matching_status_remote() -> Result<()> { async fn zenoh_matching_status_local() -> Result<()> { use flume::RecvTimeoutError; - let session1 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap(); + let session1 = ztimeout!(zenoh::open(config::peer())).unwrap(); - let session2 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap(); + let session2 = ztimeout!(zenoh::open(config::peer())).unwrap(); let publisher1 = ztimeout!(session1 .declare_publisher("zenoh_matching_status_local_test") - .allowed_destination(Locality::SessionLocal) - .res_async()) + .allowed_destination(Locality::SessionLocal)) .unwrap(); - let matching_listener = ztimeout!(publisher1.matching_listener().res_async()).unwrap(); + let matching_listener = ztimeout!(publisher1.matching_listener()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.err() == Some(RecvTimeoutError::Timeout)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - let sub = ztimeout!(session1 - .declare_subscriber("zenoh_matching_status_local_test") - .res_async()) - .unwrap(); + let sub = ztimeout!(session1.declare_subscriber("zenoh_matching_status_local_test")).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(matching_status.matching_subscribers()); - ztimeout!(sub.undeclare().res_async()).unwrap(); + ztimeout!(sub.undeclare()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - let sub = ztimeout!(session2 - .declare_subscriber("zenoh_matching_status_local_test") - .res_async()) - .unwrap(); + let sub = ztimeout!(session2.declare_subscriber("zenoh_matching_status_local_test")).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.err() == Some(RecvTimeoutError::Timeout)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); - ztimeout!(sub.undeclare().res_async()).unwrap(); + ztimeout!(sub.undeclare()).unwrap(); let received_status = matching_listener.recv_timeout(RECV_TIMEOUT); assert!(received_status.err() == Some(RecvTimeoutError::Timeout)); - let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap(); + let matching_status = ztimeout!(publisher1.matching_status()).unwrap(); assert!(!matching_status.matching_subscribers()); Ok(()) diff --git a/zenoh/tests/qos.rs b/zenoh/tests/qos.rs index 1885c316ea..f5a7718b43 100644 --- a/zenoh/tests/qos.rs +++ b/zenoh/tests/qos.rs @@ -21,34 +21,32 @@ const SLEEP: Duration = Duration::from_secs(1); #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn pubsub() { - let session1 = ztimeout!(zenoh::open(zenoh_config::peer()).res_async()).unwrap(); - let session2 = ztimeout!(zenoh::open(zenoh_config::peer()).res_async()).unwrap(); + let session1 = ztimeout!(zenoh::open(zenoh_config::peer())).unwrap(); + let session2 = ztimeout!(zenoh::open(zenoh_config::peer())).unwrap(); let publisher1 = ztimeout!(session1 .declare_publisher("test/qos") .priority(Priority::DataHigh) - .congestion_control(CongestionControl::Drop) - .res()) + .congestion_control(CongestionControl::Drop)) .unwrap(); let publisher2 = ztimeout!(session1 .declare_publisher("test/qos") .priority(Priority::DataLow) - .congestion_control(CongestionControl::Block) - .res()) + .congestion_control(CongestionControl::Block)) .unwrap(); - let subscriber = ztimeout!(session2.declare_subscriber("test/qos").res()).unwrap(); + let subscriber = ztimeout!(session2.declare_subscriber("test/qos")).unwrap(); tokio::time::sleep(SLEEP).await; - ztimeout!(publisher1.put("qos").res_async()).unwrap(); + ztimeout!(publisher1.put("qos")).unwrap(); let sample = ztimeout!(subscriber.recv_async()).unwrap(); let qos = sample.qos(); assert_eq!(qos.priority(), Priority::DataHigh); assert_eq!(qos.congestion_control(), CongestionControl::Drop); - ztimeout!(publisher2.put("qos").res_async()).unwrap(); + ztimeout!(publisher2.put("qos")).unwrap(); let sample = ztimeout!(subscriber.recv_async()).unwrap(); let qos = sample.qos(); diff --git a/zenoh/tests/routing.rs b/zenoh/tests/routing.rs index 6d7eab886a..743ce10a3a 100644 --- a/zenoh/tests/routing.rs +++ b/zenoh/tests/routing.rs @@ -50,7 +50,7 @@ impl Task { match self { // The Sub task checks if the incoming message matches the expected size until it receives enough counts. Self::Sub(ke, expected_size) => { - let sub = ztimeout!(session.declare_subscriber(ke).res_async())?; + let sub = ztimeout!(session.declare_subscriber(ke))?; let mut counter = 0; loop { tokio::select! { @@ -82,8 +82,7 @@ impl Task { // WARN: this won't yield after a timeout since the put is a blocking call res = tokio::time::timeout(std::time::Duration::from_secs(1), session .put(ke, vec![0u8; *payload_size]) - .congestion_control(CongestionControl::Block) - .res()) => { + .congestion_control(CongestionControl::Block).into_future()) => { let _ = res?; } } @@ -97,7 +96,7 @@ impl Task { while counter < MSG_COUNT { tokio::select! { _ = token.cancelled() => break, - replies = session.get(ke).timeout(Duration::from_secs(10)).res() => { + replies = session.get(ke).timeout(Duration::from_secs(10)).into_future() => { let replies = replies?; while let Ok(reply) = replies.recv_async().await { match reply.result() { @@ -127,14 +126,14 @@ impl Task { // The Queryable task keeps replying to requested messages until all checkpoints are finished. Self::Queryable(ke, payload_size) => { - let queryable = session.declare_queryable(ke).res_async().await?; + let queryable = session.declare_queryable(ke).await?; let payload = vec![0u8; *payload_size]; loop { tokio::select! { _ = token.cancelled() => break, query = queryable.recv_async() => { - query?.reply(ke.to_owned(), payload.clone()).res_async().await?; + query?.reply(ke.to_owned(), payload.clone()).await?; }, } } @@ -279,7 +278,7 @@ impl Recipe { // In case of client can't connect to some peers/routers loop { - if let Ok(session) = zenoh::open(config.clone()).res_async().await { + if let Ok(session) = zenoh::open(config.clone()).await { break session.into_arc(); } else { tokio::time::sleep(Duration::from_secs(1)).await; @@ -315,11 +314,7 @@ impl Recipe { // node_task_tracker.wait().await; // Close the session once all the task assoicated with the node are done. - Arc::try_unwrap(session) - .unwrap() - .close() - .res_async() - .await?; + Arc::try_unwrap(session).unwrap().close().await?; println!("Node: {} is closed.", &node.name); Result::Ok(()) diff --git a/zenoh/tests/session.rs b/zenoh/tests/session.rs index 62890b0755..4c6df510ac 100644 --- a/zenoh/tests/session.rs +++ b/zenoh/tests/session.rs @@ -33,7 +33,7 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { .collect::>(); config.scouting.multicast.set_enabled(Some(false)).unwrap(); println!("[ ][01a] Opening peer01 session: {:?}", endpoints); - let peer01 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let peer01 = ztimeout!(zenoh::open(config)).unwrap(); let mut config = config::peer(); config.connect.endpoints = endpoints @@ -42,7 +42,7 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { .collect::>(); config.scouting.multicast.set_enabled(Some(false)).unwrap(); println!("[ ][02a] Opening peer02 session: {:?}", endpoints); - let peer02 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let peer02 = ztimeout!(zenoh::open(config)).unwrap(); (peer01, peer02) } @@ -53,22 +53,22 @@ async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session, config.listen.endpoints = vec![endpoint01.parse().unwrap()]; config.scouting.multicast.set_enabled(Some(true)).unwrap(); println!("[ ][01a] Opening peer01 session: {}", endpoint01); - let peer01 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let peer01 = ztimeout!(zenoh::open(config)).unwrap(); let mut config = config::peer(); config.listen.endpoints = vec![endpoint02.parse().unwrap()]; config.scouting.multicast.set_enabled(Some(true)).unwrap(); println!("[ ][02a] Opening peer02 session: {}", endpoint02); - let peer02 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let peer02 = ztimeout!(zenoh::open(config)).unwrap(); (peer01, peer02) } async fn close_session(peer01: Session, peer02: Session) { println!("[ ][01d] Closing peer01 session"); - ztimeout!(peer01.close().res_async()).unwrap(); + ztimeout!(peer01.close()).unwrap(); println!("[ ][02d] Closing peer02 session"); - ztimeout!(peer02.close().res_async()).unwrap(); + ztimeout!(peer02.close()).unwrap(); } async fn test_session_pubsub(peer01: &Session, peer02: &Session, reliability: Reliability) { @@ -85,13 +85,10 @@ async fn test_session_pubsub(peer01: &Session, peer02: &Session, reliability: Re // Subscribe to data println!("[PS][01b] Subscribing on peer01 session"); let c_msgs = msgs.clone(); - let sub = ztimeout!(peer01 - .declare_subscriber(key_expr) - .callback(move |sample| { - assert_eq!(sample.payload().len(), size); - c_msgs.fetch_add(1, Ordering::Relaxed); - }) - .res_async()) + let sub = ztimeout!(peer01.declare_subscriber(key_expr).callback(move |sample| { + assert_eq!(sample.payload().len(), size); + c_msgs.fetch_add(1, Ordering::Relaxed); + })) .unwrap(); // Wait for the declaration to propagate @@ -102,8 +99,7 @@ async fn test_session_pubsub(peer01: &Session, peer02: &Session, reliability: Re for _ in 0..msg_count { ztimeout!(peer02 .put(key_expr, vec![0u8; size]) - .congestion_control(CongestionControl::Block) - .res_async()) + .congestion_control(CongestionControl::Block)) .unwrap(); } @@ -123,7 +119,7 @@ async fn test_session_pubsub(peer01: &Session, peer02: &Session, reliability: Re tokio::time::sleep(SLEEP).await; println!("[PS][03b] Unsubscribing on peer01 session"); - ztimeout!(sub.undeclare().res_async()).unwrap(); + ztimeout!(sub.undeclare()).unwrap(); // Wait for the declaration to propagate tokio::time::sleep(SLEEP).await; @@ -144,43 +140,36 @@ async fn test_session_qryrep(peer01: &Session, peer02: &Session, reliability: Re // Queryable to data println!("[QR][01c] Queryable on peer01 session"); let c_msgs = msgs.clone(); - let qbl = ztimeout!(peer01 - .declare_queryable(key_expr) - .callback(move |query| { - c_msgs.fetch_add(1, Ordering::Relaxed); - match query.parameters().as_str() { - "ok_put" => { - tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - ztimeout!(query - .reply( - KeyExpr::try_from(key_expr).unwrap(), - vec![0u8; size].to_vec() - ) - .res_async()) - .unwrap() - }) - }); - } - "ok_del" => { - tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - ztimeout!(query.reply_del(key_expr).res_async()).unwrap() - }) - }); - } - "err" => { - let rep = Value::from(vec![0u8; size]); - tokio::task::block_in_place(|| { - tokio::runtime::Handle::current().block_on(async { - ztimeout!(query.reply_err(rep).res_async()).unwrap() - }) - }); - } - _ => panic!("Unknown query parameter"), + let qbl = ztimeout!(peer01.declare_queryable(key_expr).callback(move |query| { + c_msgs.fetch_add(1, Ordering::Relaxed); + match query.parameters().as_str() { + "ok_put" => { + tokio::task::block_in_place(|| { + tokio::runtime::Handle::current().block_on(async { + ztimeout!(query.reply( + KeyExpr::try_from(key_expr).unwrap(), + vec![0u8; size].to_vec() + )) + .unwrap() + }) + }); } - }) - .res_async()) + "ok_del" => { + tokio::task::block_in_place(|| { + tokio::runtime::Handle::current() + .block_on(async { ztimeout!(query.reply_del(key_expr)).unwrap() }) + }); + } + "err" => { + let rep = Value::from(vec![0u8; size]); + tokio::task::block_in_place(|| { + tokio::runtime::Handle::current() + .block_on(async { ztimeout!(query.reply_err(rep)).unwrap() }) + }); + } + _ => panic!("Unknown query parameter"), + } + })) .unwrap(); // Wait for the declaration to propagate @@ -191,7 +180,7 @@ async fn test_session_qryrep(peer01: &Session, peer02: &Session, reliability: Re let mut cnt = 0; for _ in 0..msg_count { let selector = format!("{}?ok_put", key_expr); - let rs = ztimeout!(peer02.get(selector).res_async()).unwrap(); + let rs = ztimeout!(peer02.get(selector)).unwrap(); while let Ok(s) = ztimeout!(rs.recv_async()) { let s = s.result().unwrap(); assert_eq!(s.kind(), SampleKind::Put); @@ -209,7 +198,7 @@ async fn test_session_qryrep(peer01: &Session, peer02: &Session, reliability: Re let mut cnt = 0; for _ in 0..msg_count { let selector = format!("{}?ok_del", key_expr); - let rs = ztimeout!(peer02.get(selector).res_async()).unwrap(); + let rs = ztimeout!(peer02.get(selector)).unwrap(); while let Ok(s) = ztimeout!(rs.recv_async()) { let s = s.result().unwrap(); assert_eq!(s.kind(), SampleKind::Delete); @@ -227,7 +216,7 @@ async fn test_session_qryrep(peer01: &Session, peer02: &Session, reliability: Re let mut cnt = 0; for _ in 0..msg_count { let selector = format!("{}?err", key_expr); - let rs = ztimeout!(peer02.get(selector).res_async()).unwrap(); + let rs = ztimeout!(peer02.get(selector)).unwrap(); while let Ok(s) = ztimeout!(rs.recv_async()) { let e = s.result().unwrap_err(); assert_eq!(e.payload().len(), size); @@ -239,7 +228,7 @@ async fn test_session_qryrep(peer01: &Session, peer02: &Session, reliability: Re assert_eq!(cnt, msg_count); println!("[PS][03c] Unqueryable on peer01 session"); - ztimeout!(qbl.undeclare().res_async()).unwrap(); + ztimeout!(qbl.undeclare()).unwrap(); // Wait for the declaration to propagate tokio::time::sleep(SLEEP).await; @@ -291,11 +280,11 @@ async fn open_session_unicast_runtime(endpoints: &[&str]) -> (Runtime, Runtime) async fn zenoh_2sessions_1runtime_init() { let (r1, r2) = open_session_unicast_runtime(&["tcp/127.0.0.1:17449"]).await; println!("[RI][02a] Creating peer01 session from runtime 1"); - let peer01 = zenoh::init(r1.clone()).res_async().await.unwrap(); + let peer01 = zenoh::init(r1.clone()).await.unwrap(); println!("[RI][02b] Creating peer02 session from runtime 2"); - let peer02 = zenoh::init(r2.clone()).res_async().await.unwrap(); + let peer02 = zenoh::init(r2.clone()).await.unwrap(); println!("[RI][02c] Creating peer01a session from runtime 1"); - let peer01a = zenoh::init(r1.clone()).res_async().await.unwrap(); + let peer01a = zenoh::init(r1.clone()).await.unwrap(); println!("[RI][03c] Closing peer01a session"); std::mem::drop(peer01a); test_session_pubsub(&peer01, &peer02, Reliability::Reliable).await; diff --git a/zenoh/tests/unicity.rs b/zenoh/tests/unicity.rs index 83c6f230ca..5c6bef1b22 100644 --- a/zenoh/tests/unicity.rs +++ b/zenoh/tests/unicity.rs @@ -29,14 +29,14 @@ async fn open_p2p_sessions() -> (Session, Session, Session) { config.listen.endpoints = vec!["tcp/127.0.0.1:27447".parse().unwrap()]; config.scouting.multicast.set_enabled(Some(false)).unwrap(); println!("[ ][01a] Opening s01 session"); - let s01 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s01 = ztimeout!(zenoh::open(config)).unwrap(); let mut config = config::peer(); config.listen.endpoints = vec!["tcp/127.0.0.1:27448".parse().unwrap()]; config.connect.endpoints = vec!["tcp/127.0.0.1:27447".parse().unwrap()]; config.scouting.multicast.set_enabled(Some(false)).unwrap(); println!("[ ][02a] Opening s02 session"); - let s02 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s02 = ztimeout!(zenoh::open(config)).unwrap(); let mut config = config::peer(); config.connect.endpoints = vec![ @@ -45,7 +45,7 @@ async fn open_p2p_sessions() -> (Session, Session, Session) { ]; config.scouting.multicast.set_enabled(Some(false)).unwrap(); println!("[ ][03a] Opening s03 session"); - let s03 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s03 = ztimeout!(zenoh::open(config)).unwrap(); (s01, s02, s03) } @@ -57,38 +57,38 @@ async fn open_router_session() -> Session { config.listen.endpoints = vec!["tcp/127.0.0.1:37447".parse().unwrap()]; config.scouting.multicast.set_enabled(Some(false)).unwrap(); println!("[ ][00a] Opening router session"); - ztimeout!(zenoh::open(config).res_async()).unwrap() + ztimeout!(zenoh::open(config)).unwrap() } async fn close_router_session(s: Session) { println!("[ ][01d] Closing router session"); - ztimeout!(s.close().res_async()).unwrap(); + ztimeout!(s.close()).unwrap(); } async fn open_client_sessions() -> (Session, Session, Session) { // Open the sessions let config = config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); println!("[ ][01a] Opening s01 session"); - let s01 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s01 = ztimeout!(zenoh::open(config)).unwrap(); let config = config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); println!("[ ][02a] Opening s02 session"); - let s02 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s02 = ztimeout!(zenoh::open(config)).unwrap(); let config = config::client(["tcp/127.0.0.1:37447".parse::().unwrap()]); println!("[ ][03a] Opening s03 session"); - let s03 = ztimeout!(zenoh::open(config).res_async()).unwrap(); + let s03 = ztimeout!(zenoh::open(config)).unwrap(); (s01, s02, s03) } async fn close_sessions(s01: Session, s02: Session, s03: Session) { println!("[ ][01d] Closing s01 session"); - ztimeout!(s01.close().res_async()).unwrap(); + ztimeout!(s01.close()).unwrap(); println!("[ ][02d] Closing s02 session"); - ztimeout!(s02.close().res_async()).unwrap(); + ztimeout!(s02.close()).unwrap(); println!("[ ][03d] Closing s03 session"); - ztimeout!(s03.close().res_async()).unwrap(); + ztimeout!(s03.close()).unwrap(); } async fn test_unicity_pubsub(s01: &Session, s02: &Session, s03: &Session) { @@ -104,25 +104,19 @@ async fn test_unicity_pubsub(s01: &Session, s02: &Session, s03: &Session) { // Subscribe to data println!("[PS][01b] Subscribing on s01 session"); let c_msgs1 = msgs1.clone(); - let sub1 = ztimeout!(s01 - .declare_subscriber(key_expr) - .callback(move |sample| { - assert_eq!(sample.payload().len(), size); - c_msgs1.fetch_add(1, Ordering::Relaxed); - }) - .res_async()) + let sub1 = ztimeout!(s01.declare_subscriber(key_expr).callback(move |sample| { + assert_eq!(sample.payload().len(), size); + c_msgs1.fetch_add(1, Ordering::Relaxed); + })) .unwrap(); // Subscribe to data println!("[PS][02b] Subscribing on s02 session"); let c_msgs2 = msgs2.clone(); - let sub2 = ztimeout!(s02 - .declare_subscriber(key_expr) - .callback(move |sample| { - assert_eq!(sample.payload().len(), size); - c_msgs2.fetch_add(1, Ordering::Relaxed); - }) - .res_async()) + let sub2 = ztimeout!(s02.declare_subscriber(key_expr).callback(move |sample| { + assert_eq!(sample.payload().len(), size); + c_msgs2.fetch_add(1, Ordering::Relaxed); + })) .unwrap(); // Wait for the declaration to propagate @@ -133,8 +127,7 @@ async fn test_unicity_pubsub(s01: &Session, s02: &Session, s03: &Session) { for _ in 0..msg_count { ztimeout!(s03 .put(key_expr, vec![0u8; size]) - .congestion_control(CongestionControl::Block) - .res_async()) + .congestion_control(CongestionControl::Block)) .unwrap(); } @@ -162,10 +155,10 @@ async fn test_unicity_pubsub(s01: &Session, s02: &Session, s03: &Session) { assert_eq!(cnt2, msg_count); println!("[PS][02b] Unsubscribing on s02 session"); - ztimeout!(sub2.undeclare().res_async()).unwrap(); + ztimeout!(sub2.undeclare()).unwrap(); println!("[PS][01b] Unsubscribing on s01 session"); - ztimeout!(sub1.undeclare().res_async()).unwrap(); + ztimeout!(sub1.undeclare()).unwrap(); // Wait for the declaration to propagate tokio::time::sleep(SLEEP).await; @@ -186,42 +179,34 @@ async fn test_unicity_qryrep(s01: &Session, s02: &Session, s03: &Session) { println!("[QR][01c] Queryable on s01 session"); let cke = key_expr.clone(); let c_msgs1 = msgs1.clone(); - let qbl1 = ztimeout!(s01 - .declare_queryable(cke.clone()) - .callback(move |sample| { - c_msgs1.fetch_add(1, Ordering::Relaxed); - tokio::task::block_in_place({ - let cke2 = cke.clone(); - move || { - Handle::current().block_on(async move { - ztimeout!(sample.reply(cke2.clone(), vec![0u8; size]).res_async()) - .unwrap() - }); - } - }); - }) - .res_async()) + let qbl1 = ztimeout!(s01.declare_queryable(cke.clone()).callback(move |sample| { + c_msgs1.fetch_add(1, Ordering::Relaxed); + tokio::task::block_in_place({ + let cke2 = cke.clone(); + move || { + Handle::current().block_on(async move { + ztimeout!(sample.reply(cke2.clone(), vec![0u8; size])).unwrap() + }); + } + }); + })) .unwrap(); // Queryable to data println!("[QR][02c] Queryable on s02 session"); let cke = key_expr.clone(); let c_msgs2 = msgs2.clone(); - let qbl2 = ztimeout!(s02 - .declare_queryable(cke.clone()) - .callback(move |sample| { - c_msgs2.fetch_add(1, Ordering::Relaxed); - tokio::task::block_in_place({ - let cke2 = cke.clone(); - move || { - Handle::current().block_on(async move { - ztimeout!(sample.reply(cke2.clone(), vec![0u8; size]).res_async()) - .unwrap() - }); - } - }); - }) - .res_async()) + let qbl2 = ztimeout!(s02.declare_queryable(cke.clone()).callback(move |sample| { + c_msgs2.fetch_add(1, Ordering::Relaxed); + tokio::task::block_in_place({ + let cke2 = cke.clone(); + move || { + Handle::current().block_on(async move { + ztimeout!(sample.reply(cke2.clone(), vec![0u8; size])).unwrap() + }); + } + }); + })) .unwrap(); // Wait for the declaration to propagate @@ -232,7 +217,7 @@ async fn test_unicity_qryrep(s01: &Session, s02: &Session, s03: &Session) { let cke = key_expr.clone(); let mut cnt = 0; for _ in 0..msg_count { - let rs = ztimeout!(s03.get(cke.clone()).res_async()).unwrap(); + let rs = ztimeout!(s03.get(cke.clone())).unwrap(); while let Ok(s) = ztimeout!(rs.recv_async()) { assert_eq!(s.result().unwrap().payload().len(), size); cnt += 1; @@ -248,10 +233,10 @@ async fn test_unicity_qryrep(s01: &Session, s02: &Session, s03: &Session) { assert_eq!(cnt, msg_count); println!("[PS][01c] Unqueryable on s01 session"); - ztimeout!(qbl1.undeclare().res_async()).unwrap(); + ztimeout!(qbl1.undeclare()).unwrap(); println!("[PS][02c] Unqueryable on s02 session"); - ztimeout!(qbl2.undeclare().res_async()).unwrap(); + ztimeout!(qbl2.undeclare()).unwrap(); // Wait for the declaration to propagate tokio::time::sleep(SLEEP).await;