-
Notifications
You must be signed in to change notification settings - Fork 85
Add getNextCallTime() into Timer #1356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -101,7 +101,10 @@ Napi::Value CreateTimer(const Napi::CallbackInfo& info) { | |||
| #if ROS_VERSION > 2205 | ||||
| // Clear the callback first to prevent any new callbacks from being | ||||
| // triggered | ||||
| rcl_timer_set_on_reset_callback(timer, nullptr, nullptr); | ||||
| rcl_ret_t callback_ret = | ||||
| rcl_timer_set_on_reset_callback(timer, nullptr, nullptr); | ||||
| (void)callback_ret; // Suppress unused variable warning if error | ||||
| // handling is not needed | ||||
| #endif | ||||
|
|
||||
| std::shared_ptr<TimerContext> context; | ||||
|
|
@@ -254,6 +257,24 @@ Napi::Value GetTimerPeriod(const Napi::CallbackInfo& info) { | |||
| return Napi::BigInt::New(env, period_nsec); | ||||
| } | ||||
|
|
||||
| Napi::Value GetTimerNextCallTime(const Napi::CallbackInfo& info) { | ||||
| Napi::Env env = info.Env(); | ||||
| RclHandle* timer_handle = RclHandle::Unwrap(info[0].As<Napi::Object>()); | ||||
| rcl_timer_t* timer = reinterpret_cast<rcl_timer_t*>(timer_handle->ptr()); | ||||
| int64_t next_call_time = 0; | ||||
|
|
||||
| rcl_ret_t ret = rcl_timer_get_next_call_time(timer, &next_call_time); | ||||
|
|
||||
| if (ret == RCL_RET_OK) { | ||||
| return Napi::BigInt::New(env, next_call_time); | ||||
| } else if (ret == RCL_RET_TIMER_CANCELED) { | ||||
| return env.Null(); | ||||
| } else { | ||||
| THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, ret, rcl_get_error_string().str); | ||||
| return env.Undefined(); | ||||
|
||||
| return env.Undefined(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
callback_retis assigned but only used with a void cast to suppress warnings. While the comment explains this is intentional, silently ignoring the return value fromrcl_timer_set_on_reset_callbackcould mask legitimate errors during timer cleanup. Consider logging the error or at minimum documenting why it's safe to ignore this specific error condition.