Skip to content

Commit 947aa26

Browse files
wayneparrottminggangw
authored andcommitted
Support Node#spinning properly
* Converted Node.js `spinning` property to getter * Updated node.d.ts * Added tests for spinning getter Fix #837
1 parent 8819560 commit 947aa26

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

lib/node.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Node extends rclnodejs.ShadowNode {
102102
this._parameterEventPublisher = null;
103103
this._setParametersCallbacks = [];
104104
this._logger = new Logging(rclnodejs.getNodeLoggerName(this.handle));
105-
this.spinning = false;
105+
this._spinning = false;
106106

107107
this._parameterEventPublisher = this.createPublisher(
108108
PARAMETER_EVENT_MSG_TYPE,
@@ -375,6 +375,14 @@ class Node extends rclnodejs.ShadowNode {
375375
});
376376
}
377377

378+
/**
379+
* Determine if this node is spinning.
380+
* @returns {boolean} - true when spinning; otherwise returns false.
381+
*/
382+
get spinning() {
383+
return this._spinning;
384+
}
385+
378386
/**
379387
* Trigger the event loop to continuously check for and route.
380388
* incoming events.
@@ -388,7 +396,7 @@ class Node extends rclnodejs.ShadowNode {
388396
throw new Error('The node is already spinning.');
389397
}
390398
this.start(this.context.handle, timeout);
391-
this.spinning = true;
399+
this._spinning = true;
392400
}
393401

394402
/**
@@ -401,21 +409,21 @@ class Node extends rclnodejs.ShadowNode {
401409

402410
/**
403411
* Terminate spinning - no further events will be received.
404-
* @returns {undfined}
412+
* @returns {undefined}
405413
*/
406414
stop() {
407415
super.stop();
408-
this.spinning = false;
416+
this._spinning = false;
409417
}
410418

411419
/**
412420
* Terminate spinning - no further events will be received.
413-
* @returns {undfined}
421+
* @returns {undefined}
414422
* @deprecated since 0.18.0, Use stop().
415423
*/
416424
stopSpinning() {
417425
super.stop();
418-
this.spinning = false;
426+
this._spinning = false;
419427
}
420428

421429
/**

test/test-node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ describe('Test the node with no handles attached when initializing', function ()
489489
new NodeOptions(false, [], false)
490490
);
491491
const str = 'hello world';
492+
493+
assert.ok(!node.spinning);
492494
rclnodejs.spin(node);
495+
assert.ok(node.spinning);
493496

494497
setTimeout(() => {
495498
const publisher = node.createPublisher('std_msgs/msg/String', 'chatter');

test/types/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ node.getLogger();
5555
node.getClock();
5656

5757
// $ExpectType void
58-
rclnodejs.spin(node);
58+
node.spin();
59+
60+
// $ExpectType void
61+
node.spinOnce();
62+
63+
// $ExpectType boolean
64+
node.spinning;
5965

6066
// $ExpectType void
6167
node.destroy();

types/node.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ declare module 'rclnodejs' {
182182
*/
183183
options(): NodeOptions;
184184

185+
/**
186+
* Determine if this node is spinning.
187+
*
188+
* @returns true when spinning; otherwise returns false.
189+
*/
190+
get spinning(): boolean;
191+
185192
/**
186193
* Trigger the event loop to continuously check for and route.
187194
* incoming events.

0 commit comments

Comments
 (0)