@@ -16,24 +16,21 @@ import Ros from "./Ros.js";
1616export default class Service < TRequest , TResponse > extends EventEmitter {
1717 /**
1818 * Stores a reference to the most recent service callback advertised so it can be removed from the EventEmitter during un-advertisement
19- * @private
2019 */
21- _serviceCallback :
20+ #serviceCallback :
2221 | ( (
2322 rosbridgeRequest : RosbridgeCallServiceMessage < TRequest > ,
2423 ) => void | Promise < void > )
2524 | null = null ;
2625 isAdvertised = false ;
2726 /**
2827 * Queue for serializing advertise/unadvertise operations to prevent race conditions
29- * @private
3028 */
31- _operationQueue = Promise . resolve ( ) ;
29+ #operationQueue = Promise . resolve ( ) ;
3230 /**
3331 * Track if an unadvertise operation is pending to prevent double operations
34- * @private
3532 */
36- _pendingUnadvertise = false ;
33+ #pendingUnadvertise = false ;
3734 ros : Ros ;
3835 name : string ;
3936 serviceType : string ;
@@ -115,15 +112,15 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
115112 callback : ( request : TRequest , response : Partial < TResponse > ) => boolean ,
116113 ) : Promise < void > {
117114 // Queue this operation to prevent race conditions
118- this . _operationQueue = this . _operationQueue
115+ this . #operationQueue = this . #operationQueue
119116 . then ( async ( ) => {
120117 // If already advertised, unadvertise first
121118 if ( this . isAdvertised ) {
122- await this . _doUnadvertise ( ) ;
119+ await this . #doUnadvertise ( ) ;
123120 }
124121
125122 // Store the new callback for removal during un-advertisement
126- this . _serviceCallback = ( rosbridgeRequest ) => {
123+ this . #serviceCallback = ( rosbridgeRequest ) => {
127124 const response = { } ;
128125 let success : boolean ;
129126 try {
@@ -150,7 +147,7 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
150147 }
151148 } ;
152149
153- this . ros . on ( this . name , this . _serviceCallback ) ;
150+ this . ros . on ( this . name , this . #serviceCallback ) ;
154151 this . ros . callOnConnection ( {
155152 op : "advertise_service" ,
156153 type : this . serviceType ,
@@ -163,19 +160,18 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
163160 throw err ;
164161 } ) ;
165162
166- return this . _operationQueue ;
163+ return this . #operationQueue ;
167164 }
168165
169166 /**
170167 * Internal method to perform unadvertisement without queueing
171- * @private
172168 */
173- async _doUnadvertise ( ) {
174- if ( ! this . isAdvertised || this . _pendingUnadvertise ) {
169+ async #doUnadvertise ( ) {
170+ if ( ! this . isAdvertised || this . #pendingUnadvertise ) {
175171 return ;
176172 }
177173
178- this . _pendingUnadvertise = true ;
174+ this . #pendingUnadvertise = true ;
179175
180176 try {
181177 /*
@@ -185,9 +181,9 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
185181 this . isAdvertised = false ;
186182
187183 // Remove the registered callback to stop processing new requests
188- if ( this . _serviceCallback ) {
189- this . ros . off ( this . name , this . _serviceCallback ) ;
190- this . _serviceCallback = null ;
184+ if ( this . #serviceCallback ) {
185+ this . ros . off ( this . name , this . #serviceCallback ) ;
186+ this . #serviceCallback = null ;
191187 }
192188
193189 /*
@@ -200,22 +196,22 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
200196 service : this . name ,
201197 } ) ;
202198 } finally {
203- this . _pendingUnadvertise = false ;
199+ this . #pendingUnadvertise = false ;
204200 }
205201 }
206202
207203 async unadvertise ( ) : Promise < void > {
208204 // Queue this operation to prevent race conditions
209- this . _operationQueue = this . _operationQueue
205+ this . #operationQueue = this . #operationQueue
210206 . then ( async ( ) => {
211- await this . _doUnadvertise ( ) ;
207+ await this . #doUnadvertise ( ) ;
212208 } )
213209 . catch ( ( err ) => {
214210 this . emit ( "error" , err ) ;
215211 throw err ;
216212 } ) ;
217213
218- return this . _operationQueue ;
214+ return this . #operationQueue ;
219215 }
220216
221217 /**
@@ -226,14 +222,14 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
226222 callback : ( request : TRequest ) => Promise < TResponse > ,
227223 ) : Promise < void > {
228224 // Queue this operation to prevent race conditions
229- this . _operationQueue = this . _operationQueue
225+ this . #operationQueue = this . #operationQueue
230226 . then ( async ( ) => {
231227 // If already advertised, unadvertise first
232228 if ( this . isAdvertised ) {
233- await this . _doUnadvertise ( ) ;
229+ await this . #doUnadvertise ( ) ;
234230 }
235231
236- this . _serviceCallback = async ( rosbridgeRequest ) => {
232+ this . #serviceCallback = async ( rosbridgeRequest ) => {
237233 try {
238234 this . ros . callOnConnection ( {
239235 op : "service_response" ,
@@ -252,7 +248,7 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
252248 } satisfies RosbridgeServiceResponseMessage < TResponse > ) ;
253249 }
254250 } ;
255- this . ros . on ( this . name , this . _serviceCallback ) ;
251+ this . ros . on ( this . name , this . #serviceCallback ) ;
256252 this . ros . callOnConnection ( {
257253 op : "advertise_service" ,
258254 type : this . serviceType ,
@@ -265,6 +261,6 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
265261 throw err ;
266262 } ) ;
267263
268- return this . _operationQueue ;
264+ return this . #operationQueue ;
269265 }
270266}
0 commit comments