@@ -22,14 +22,14 @@ const msgUtils = require('../utils/message_utils.js');
2222const ActionClientInterface = require ( '../lib/ActionClientInterface.js' ) ;
2323
2424const EventEmitter = require ( 'events' ) ;
25+ const Ultron = require ( 'ultron' ) ;
2526
2627const ClientGoalHandle = require ( './ClientGoalHandle.js' ) ;
2728const Time = require ( '../lib/Time.js' ) ;
2829
2930const log = require ( '../lib/Logging.js' ) . getLogger ( 'actionlib_nodejs' ) ;
3031const ThisNode = require ( '../lib/ThisNode.js' ) ;
31-
32- let GOAL_COUNT = 0 ;
32+ const GoalIdGenerator = require ( './GoalIdGenerator.js' ) ;
3333
3434/**
3535 * @class ActionClient
@@ -57,10 +57,27 @@ class ActionClient extends EventEmitter {
5757 } ;
5858
5959 this . _goalLookup = { } ;
60+
61+ this . _shutdown = false ;
62+ this . _ultron = new Ultron ( ThisNode ) ;
63+
64+ // FIXME: how to handle shutdown? Should user be responsible?
65+ // should we check for shutdown in interval instead of listening
66+ // to events here?
67+ this . _ultron . once ( 'shutdown' , ( ) => { this . shutdown ( ) ; } ) ;
6068 }
6169
6270 shutdown ( ) {
63- return this . _acInterface . shutdown ( ) ;
71+ if ( ! this . _shutdown ) {
72+ this . _shutdown = true ;
73+
74+ this . _ultron . destroy ( ) ;
75+ this . _ultron = null ;
76+
77+ return this . _acInterface . shutdown ( ) ;
78+ }
79+ // else
80+ return Promise . resolve ( ) ;
6481 }
6582
6683 sendGoal ( goal , transitionCb = null , feedbackCb = null ) {
@@ -69,7 +86,7 @@ class ActionClient extends EventEmitter {
6986 const now = Time . now ( ) ;
7087 actionGoal . header . stamp = now ;
7188 actionGoal . goal_id . stamp = now ;
72- const goalIdStr = ` ${ ThisNode . getNodeName ( ) } - ${ GOAL_COUNT ++ } - ${ now . secs } . ${ now . nsecs } ` ;
89+ const goalIdStr = GoalIdGenerator ( now ) ;
7390 actionGoal . goal_id . id = goalIdStr ;
7491 actionGoal . goal = goal ;
7592
0 commit comments