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

RobotWebTools / rclnodejs / 20290231101

17 Dec 2025 03:06AM UTC coverage: 80.429% (+0.03%) from 80.404%
20290231101

Pull #1356

github

web-flow
Merge e19bcff91 into be8615a38
Pull Request #1356: Add getNextCallTime() into Timer

1240 of 1718 branches covered (72.18%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

6 existing lines in 1 file now uncovered.

2664 of 3136 relevant lines covered (84.95%)

455.22 hits per line

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

74.29
/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;
60✔
28
    this._period = period;
60✔
29
    this.callback = callback;
60✔
30
  }
31

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

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

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

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

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

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

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

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

91
  /**
92
   * Get the absolute time in nanoseconds when the next callback is due.
93
   * @return {bigint | null} - The next call time in nanoseconds, or null if the timer is canceled.
94
   */
95
  getNextCallTime() {
96
    return rclnodejs.getTimerNextCallTime(this._handle);
2✔
97
  }
98

99
  /**
100
   * Change the timer period.
101
   * @param {bigint} period - The new period in nanoseconds.
102
   * @return {undefined}
103
   */
104
  changeTimerPeriod(period) {
105
    rclnodejs.changeTimerPeriod(this._handle, period);
1✔
106
  }
107

108
  /**
109
   * Get the timer period.
110
   * @return {bigint} - The period in nanoseconds.
111
   */
112
  get timerPeriod() {
113
    return rclnodejs.getTimerPeriod(this._handle);
2✔
114
  }
115

116
  /**
117
   * Set the on reset callback.
118
   * @param {function} callback - The callback to be called when the timer is reset.
119
   * @return {undefined}
120
   */
121
  setOnResetCallback(callback) {
122
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
2!
UNCOV
123
      console.warn(
×
124
        'setOnResetCallback is not supported by this version of ROS 2'
125
      );
UNCOV
126
      return;
×
127
    }
128
    rclnodejs.setTimerOnResetCallback(this._handle, callback);
2✔
129
  }
130

131
  /**
132
   * Clear the on reset callback.
133
   * @return {undefined}
134
   */
135
  clearOnResetCallback() {
136
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
1!
UNCOV
137
      console.warn(
×
138
        'clearOnResetCallback is not supported by this version of ROS 2'
139
      );
UNCOV
140
      return;
×
141
    }
142
    rclnodejs.clearTimerOnResetCallback(this._handle);
1✔
143
  }
144

145
  /**
146
   * Call a timer and starts counting again, retrieves actual and expected call time.
147
   * @return {object} - The timer information.
148
   */
149
  callTimerWithInfo() {
150
    if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
1!
UNCOV
151
      console.warn(
×
152
        'callTimerWithInfo is not supported by this version of ROS 2'
153
      );
UNCOV
154
      return;
×
155
    }
156
    return rclnodejs.callTimerWithInfo(this._handle);
1✔
157
  }
158
}
159

160
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