Skip to content

Commit 63a1f9d

Browse files
committed
Skip readiness check if an error is reported
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 70cf856 commit 63a1f9d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

rclrs/src/wait_set.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,31 @@ impl WaitSet {
123123
// the waitable of each primitive to one (and only one) WaitSet when
124124
// the primitive gets constructed. The waitables are never allowed to
125125
// move between wait sets.
126-
let r = unsafe { rcl_wait(&mut self.handle.rcl_wait_set, timeout_ns) }.ok();
126+
let r = match unsafe { rcl_wait(&mut self.handle.rcl_wait_set, timeout_ns) }.ok()
127+
{
128+
Ok(_) => Ok(()),
129+
Err(error) => match error {
130+
RclrsError::RclError { code, msg } => match code {
131+
RclReturnCode::WaitSetEmpty => Ok(()),
132+
_ => Err(RclrsError::RclError { code, msg }),
133+
},
134+
_ => Err(error),
135+
},
136+
};
127137

128138
// Remove any waitables that are no longer being used
129139
for waitable in self.primitives.values_mut() {
130140
waitable.retain(|w| w.in_use());
131141
}
132142

133-
// For the remaining entities, check if they were activated and then run
134-
// the callback for those that were.
135-
for waiter in self.primitives.values_mut().flat_map(|v| v) {
136-
if waiter.is_ready(&self.handle.rcl_wait_set) {
137-
f(&mut *waiter.primitive)?;
143+
// Do not check the readiness if an error was reported.
144+
if !r.is_err() {
145+
// For the remaining entities, check if they were activated and then run
146+
// the callback for those that were.
147+
for waiter in self.primitives.values_mut().flat_map(|v| v) {
148+
if waiter.is_ready(&self.handle.rcl_wait_set) {
149+
f(&mut *waiter.primitive)?;
150+
}
138151
}
139152
}
140153

@@ -155,16 +168,7 @@ impl WaitSet {
155168
);
156169
}
157170

158-
match r {
159-
Ok(_) => Ok(()),
160-
Err(error) => match error {
161-
RclrsError::RclError { code, msg } => match code {
162-
RclReturnCode::WaitSetEmpty => Ok(()),
163-
_ => Err(RclrsError::RclError { code, msg }),
164-
},
165-
_ => Err(error),
166-
},
167-
}
171+
r
168172
}
169173

170174
/// Get a count of the different kinds of entities in the wait set.

0 commit comments

Comments
 (0)