@@ -50,8 +50,8 @@ pub use wait::*;
50
50
/// This can usually be ignored.
51
51
///
52
52
/// [1]: crate::RclReturnCode
53
- pub fn spin_once ( node : & Node , timeout : Option < Duration > ) -> Result < ( ) , RclrsError > {
54
- let wait_set = WaitSet :: new_for_node ( node) ?;
53
+ pub fn spin_once ( node : Arc < Node > , timeout : Option < Duration > ) -> Result < ( ) , RclrsError > {
54
+ let wait_set = WaitSet :: new_for_node ( & * node) ?;
55
55
let ready_entities = wait_set. wait ( timeout) ?;
56
56
57
57
for ready_subscription in ready_entities. subscriptions {
@@ -72,14 +72,16 @@ pub fn spin_once(node: &Node, timeout: Option<Duration>) -> Result<(), RclrsErro
72
72
/// Convenience function for calling [`spin_once`] in a loop.
73
73
///
74
74
/// This function additionally checks that the context is still valid.
75
- pub fn spin ( node : & Node ) -> Result < ( ) , RclrsError > {
75
+ pub fn spin ( node : Arc < Node > ) -> Result < ( ) , RclrsError > {
76
76
// The context_is_valid functions exists only to abstract away ROS distro differences
77
77
// SAFETY: No preconditions for this function.
78
- let context_is_valid =
79
- || unsafe { rcl_context_is_valid ( & * node. rcl_context_mtx . lock ( ) . unwrap ( ) ) } ;
78
+ let context_is_valid = {
79
+ let node = Arc :: clone ( & node) ;
80
+ move || unsafe { rcl_context_is_valid ( & * node. rcl_context_mtx . lock ( ) . unwrap ( ) ) }
81
+ } ;
80
82
81
83
while context_is_valid ( ) {
82
- match spin_once ( node, None ) {
84
+ match spin_once ( Arc :: clone ( & node) , None ) {
83
85
Ok ( _)
84
86
| Err ( RclrsError :: RclError {
85
87
code : RclReturnCode :: Timeout ,
0 commit comments