Skip to content

Commit

Permalink
Removed RclFuture and supporting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
esteve committed Jun 13, 2022
1 parent a988c45 commit c0f2251
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 115 deletions.
63 changes: 0 additions & 63 deletions rclrs/src/future.rs

This file was deleted.

51 changes: 0 additions & 51 deletions rclrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,54 +112,3 @@ pub fn spin(node: &Node) -> Result<(), RclrsError> {
}
Ok(())
}

/// Convenience function for calling [`rclrs::spin_once`] in a loop.
///
/// This function additionally checks that the context is still valid.
pub fn spin_some(node: &Node) -> Result<(), RclrsError> {
// The context_is_valid functions exists only to abstract away ROS distro differences
#[cfg(ros_distro = "foxy")]
// SAFETY: No preconditions for this function.
let context_is_valid = || unsafe { rcl_context_is_valid(&mut *node.context.lock()) };
#[cfg(not(ros_distro = "foxy"))]
// SAFETY: No preconditions for this function.
let context_is_valid = || unsafe { rcl_context_is_valid(&*node.context.lock()) };

if context_is_valid() {
if let Some(error) = spin_once(node, Some(std::time::Duration::from_millis(500))).err() {
match error.code {
RclReturnCode::Timeout => (),
_ => return Err(error),
}
}
}
Ok(())
}

pub fn spin_until_future_complete<T: Unpin + Clone>(
node: &node::Node,
future: Arc<Mutex<Box<crate::future::RclFuture<T>>>>,
) -> Result<<future::RclFuture<T> as Future>::Output, RclrsError> {
let rclwaker = Arc::new(crate::future::RclWaker {});
let waker = crate::future::rclwaker_into_waker(Arc::into_raw(rclwaker));
let mut cx = std::task::Context::from_waker(&waker);

loop {
let context_valid = unsafe { rcl_context_is_valid(&mut *node.context.lock()) };
if context_valid {
if let Some(error) = spin_once(node, None).err() {
match error {
RclrsError {
code: RclReturnCode::Timeout,
..
} => continue,
error => return Err(error),
};
};
match Future::poll(Pin::new(&mut *future.lock()), &mut cx) {
Poll::Ready(val) => break Ok(val),
Poll::Pending => continue,
};
}
}
}
1 change: 0 additions & 1 deletion rclrs/src/node/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::sync::atomic::{AtomicI64, Ordering};
use std::sync::Arc;

use crate::error::{RclReturnCode, ToResult};
use crate::future::RclFuture;
use crate::MessageCow;
use crate::Node;
use crate::{rcl_bindings::*, RclrsError};
Expand Down

0 comments on commit c0f2251

Please sign in to comment.