• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RobotWebTools / rclnodejs / 23333232327

20 Mar 2026 07:27AM UTC coverage: 85.995%. Remained the same
23333232327

push

github

minggangw
Update README (#1449)

Updates the project’s README content (repo README and npm package README) to reflect current supported ROS 2 distros, modernized API usage, and clearer install/docs guidance.

**Changes:**
- Refresh README messaging (supported ROS distros, reorganized documentation links, added Quick Start).
- Update README code snippets to use OO-style APIs (`new rclnodejs.Node()` + `node.spin()`).
- Improve installation/prebuilt-binary notes and clarify message generation workflow.

### Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

| File | Description |
| ---- | ----------- |
| scripts/npmjs-readme.md | Updates the npm-published README content: modernizes example code, adds docs/examples links, and documents message generation and prebuilt-binary fallback behavior. |
| README.md | Updates the repo README: supported distro note, reorganized documentation section, adds Quick Start, clarifies TypeScript typing exposure, and adds benchmark methodology disclaimer. |

Fix: #1448

1477 of 1866 branches covered (79.15%)

Branch coverage included in aggregate %.

3036 of 3382 relevant lines covered (89.77%)

454.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.87
/lib/timer.js
1
// Copyright (c) 2017 Intel Corporation. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
'use strict';
16

17
const rclnodejs = require('./native_loader.js');
26✔
18
const DistroUtils = require('./distro.js');
26✔
19

20
/**
21
 * @class - Class representing a Timer in ROS
22
 * @hideconstructor
23
 */
24

25
class Timer {
26
  constructor(handle, period, callback) {
27
    this._handle = handle;
65✔
28
    this._period = period;
65✔
29
    this.callback = callback;
65✔
30
  }
31

32
  /**
33
   * The period of the timer in nanoseconds.
34
   * @type {bigint}
35
   */
36
  get period() {
37
    return this._period;
3✔
38
  }
39

40
  get handle() {
41
    return this._handle;
9,298✔
42
  }
43

44
  /**
45
   * Check if the timer is ready.
46
   * @return {boolean} Return true if timer is ready, otherwise return false.
47
   */
48
  isReady() {
49
    return rclnodejs.isTimerReady(this._handle);
4,686✔
50
  }
51

52
  /**
53
   * Check if the timer is canceled.
54
   * @return {boolean} Return true if timer is canceled, otherwise return false.
55
   */
56
  isCanceled() {
57
    return rclnodejs.isTimerCanceled(this._handle);
3,008✔
58
  }
59

60
  /**
61
   * Cancel the timer.
62
   * @return {undefined}
63
   */
64
  cancel() {
65
    rclnodejs.cancelTimer(this._handle);
49✔
66
  }
67

68
  /**
69
   * Reset the timer.
70
   * @return {undefined}
71
   */
72
  reset() {
73
    rclnodejs.resetTimer(this._handle);
3✔
74
  }
75

76
  /**
77
   * Get the interval since the last call of this timer.
78
   * @return {bigint} - the interval value in nanoseconds.
79
   */
80
  timeSinceLastCall() {
81
    return rclnodejs.timerGetTimeSinceLastCall(this._handle);
1✔
82
  }
83

84
  /**
85
   * Get the interval until the next call will happen.
86
   * @return {bigint} - the interval value in nanoseconds.
87
   */
88
  timeUntilNextCall() {
89
    return rclnodejs.timerGetTimeUntilNextCall(this._handle);
1✔
90
  }
91

92
  /**
93
   * Get the absolute time in nanoseconds when the next callback is due.
94
   * Note: Only available on ROS2 distributions after Humble.
95
   * @return {bigint | null} - The next call time in nanoseconds, or null if the timer is canceled.
96
   *   Returns undefined if not supported on current ROS2 distribution.
97
   */
98
  getNextCallTime() {
99
    if (typeof rclnodejs.getTimerNextCallTime !== 'function') {
3!
100
      return undefined;
×
101
    }
102
    return rclnodejs.getTimerNextCallTime(this._handle);
3✔
103
  }
104

105
  /**
106
   * Change the timer period.
107
   * @param {bigint} period - The new period in nanoseconds.
108
   * @return {undefined}
109
   */
110
  changeTimerPeriod(period) {
111
    rclnodejs.changeTimerPeriod(this._handle, period);
1✔
112
  }
113

114
  /**
115
   * Get the timer period.
116
   * @return {bigint} - The period in nanoseconds.
117
   */
118
  get timerPeriod() {
119
    return rclnodejs.getTimerPeriod(this._handle);
2✔
120
  }
121

122
  /**
123
   * Set the on reset callback.
124
   * @param {function} callback - The callback to be called when the timer is reset.
125
   * @return {undefined}
126
   */
127
  setOnResetCallback(callback) {
128
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
3✔
129
      console.warn(
1✔
130
        'setOnResetCallback is not supported by this version of ROS 2'
131
      );
132
      return;
1✔
133
    }
134
    rclnodejs.setTimerOnResetCallback(this._handle, callback);
2✔
135
  }
136

137
  /**
138
   * Clear the on reset callback.
139
   * @return {undefined}
140
   */
141
  clearOnResetCallback() {
142
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
2✔
143
      console.warn(
1✔
144
        'clearOnResetCallback is not supported by this version of ROS 2'
145
      );
146
      return;
1✔
147
    }
148
    rclnodejs.clearTimerOnResetCallback(this._handle);
1✔
149
  }
150

151
  /**
152
   * Call a timer and starts counting again, retrieves actual and expected call time.
153
   * @return {object} - The timer information.
154
   */
155
  callTimerWithInfo() {
156
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
2✔
157
      console.warn(
1✔
158
        'callTimerWithInfo is not supported by this version of ROS 2'
159
      );
160
      return;
1✔
161
    }
162
    return rclnodejs.callTimerWithInfo(this._handle);
1✔
163
  }
164
}
165

166
module.exports = Timer;
26✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc