-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
following example:
pub struct ParamSubscriptionNode {
#[allow(unused)]
subscriber: WorkerSubscription<StringMsg, Option<String>>,
worker: Worker<Option<String>>,
}
impl ParamSubscriptionNode {
fn new(context: &Executor) -> Result<Self, RclrsError> {
let node = context.create_node("simple_subscription")?;
let worker = node.create_worker(None);
let subscriber = worker
.create_subscription::<StringMsg, _>(
&node
.declare_parameter("topic_name")
.default(Arc::from("publish_hello"))
.description("The name of the topic to be subscribed on. Has a default value.")
.mandatory()
.unwrap()
.get(),
move |data: &mut Option<String>, msg: StringMsg| {
*data = Some(msg.data);
},
)
.unwrap();
Ok(Self { subscriber, worker })
}
}As you can see, the struct has an entry with the #[allow(unused)] macro above it, which tells that the entry isn't used. Normally, entry's that aren't used can be dropped, because they're not needed. In this particular case, the entry is needed, because without the subscriber entry, the logger from:
fn main() -> Result<(), RclrsError> {
let mut executor = Context::default_from_env()?.create_basic_executor();
let node = ParamSubscriptionNode::new(&executor)?;
thread::spawn(move || {
loop {
thread::sleep(Duration::from_secs(1));
drop(node.worker.run(|data: &mut Option<String>| {
println!(
"{}",
match data {
Some(data) => data,
None => "No message available yet.",
}
)
}));
}
});
executor.spin(SpinOptions::default()).first_error()
}would always tell "No message available yet." even if they're catched succesfully by the worker. Why is that?
Metadata
Metadata
Assignees
Labels
No labels