pub struct SpinOptions {
pub timeout: Option<Duration>,
pub only_next: bool,
pub max_callbacks: Option<usize>,
pub poll_interval: Duration,
pub stop_on_first_error: bool,
}Expand description
Options controlling a blocking spin loop — rclrs’s SpinOptions.
Consumed by Executor::spin (runs until one of
these conditions ends it) and by
Executor::spin_forever (which can only
honour poll_interval and
stop_on_first_error — it never returns).
This type is where the RTOS divergence lives. phase-427 moved
Executor::spin onto rclrs’s name and shape so a ported rclrs file needs no
rename on that line; the two things ours must say and rclrs’s has no field
for — how long one iteration may wait on the transport, and whether a failed
callback ends the loop — are fields HERE rather than extra verbs. The three
fields rclrs does have (timeout, only_next, max_callbacks) keep their
upstream meaning.
Fields§
§timeout: Option<Duration>Stop after this duration.
phase-379 W5 — a Duration, not a u64 of milliseconds. The _ms
suffix was inconsistent with the two methods that consume these options
(Executor::spin_once and Executor::spin already take
core::time::Duration) as well as with rclrs’s SpinOptions::timeout.
Milliseconds ARE the unit the platform ABI’s wait primitives take, but
that conversion belongs at the ABI boundary, where it already happens —
not in the public option a user writes.
only_next: boolOnly process immediately available work (single iteration)
max_callbacks: Option<usize>Stop after processing this many callbacks total
poll_interval: DurationOURS-ONLY — how long one iteration may wait on the transport.
Each pass of the loop is spin_once(poll_interval), so this is the
granularity at which every OTHER exit condition here is observed: a
cancel() from another task, a timeout expiring, max_callbacks
being reached. rclrs has no counterpart because its executor waits on a
wait-set with no such quantum; ours is a poll loop by RFC-0002, and the
quantum is a real number a caller has to be able to set.
Defaults to DEFAULT_SPIN_POLL_INTERVAL (10 ms).
stop_on_first_error: boolOURS-ONLY — end the loop at the first pass in which a callback failed.
rclrs collects every callback error into the Vec<RclrsError> its
spin returns and the caller picks with .first_error(). There is no
allocator here, so ours returns Result<(), NodeError> carrying the
FIRST error — and a channel that can hold one error has to say when it
stops looking. false (the default) keeps today’s behaviour: a failed
callback is counted in SpinOnceResult and the loop continues.
Implementations§
Source§impl SpinOptions
impl SpinOptions
Sourcepub const fn new() -> SpinOptions
pub const fn new() -> SpinOptions
Create default spin options (spin forever until halted)
Sourcepub const fn timeout(self, timeout: Duration) -> SpinOptions
pub const fn timeout(self, timeout: Duration) -> SpinOptions
Set a timeout duration.
Matches rclrs’s SpinOptions::timeout(Duration). Stays const — ours
is a strict superset there, and Duration::from_millis is const-stable
well below this workspace’s MSRV, so SpinOptions::new().timeout( Duration::from_millis(50)) is usable in a const context.
Sourcepub const fn spin_once() -> SpinOptions
pub const fn spin_once() -> SpinOptions
Only process one round of work (equivalent to spin_once)
Sourcepub const fn max_callbacks(self, n: usize) -> SpinOptions
pub const fn max_callbacks(self, n: usize) -> SpinOptions
Stop after processing N callbacks
Sourcepub const fn poll_interval(self, poll_interval: Duration) -> SpinOptions
pub const fn poll_interval(self, poll_interval: Duration) -> SpinOptions
Set the per-iteration transport budget. See
poll_interval.
Sourcepub const fn stop_on_first_error(self, stop: bool) -> SpinOptions
pub const fn stop_on_first_error(self, stop: bool) -> SpinOptions
End the loop at the first failed callback. See
stop_on_first_error.
Trait Implementations§
Source§impl Clone for SpinOptions
impl Clone for SpinOptions
Source§fn clone(&self) -> SpinOptions
fn clone(&self) -> SpinOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SpinOptions
impl Debug for SpinOptions
Source§impl Default for SpinOptions
impl Default for SpinOptions
Source§fn default() -> SpinOptions
fn default() -> SpinOptions
Not derived: Duration::default() is ZERO, which would turn every
SpinOptions::default() spin into a busy-poll.