@@ -184,11 +184,17 @@ impl Node {
184184 ///
185185 /// [1]: crate::Client
186186 // TODO: make client's lifetime depend on node's lifetime
187- pub fn create_client < T > ( & mut self , topic : & str ) -> Result < Arc < Client < T > > , RclrsError >
187+ pub fn create_client < T > (
188+ & mut self ,
189+ topic : & str ,
190+ ) -> Result < Arc < crate :: node:: client:: Client < T > > , RclrsError >
188191 where
189192 T : rosidl_runtime_rs:: Service ,
190193 {
191- Client :: < T > :: new ( self , topic)
194+ let client = Arc :: new ( crate :: node:: client:: Client :: < T > :: new ( self , topic) ?) ;
195+ self . clients
196+ . push ( Arc :: downgrade ( & client) as Weak < dyn ClientBase > ) ;
197+ Ok ( client)
192198 }
193199
194200 /// Creates a [`Publisher`][1].
@@ -214,12 +220,17 @@ impl Node {
214220 & mut self ,
215221 topic : & str ,
216222 callback : F ,
217- ) -> Result < Arc < Service < T > > , RclrsError >
223+ ) -> Result < Arc < crate :: node :: service :: Service < T > > , RclrsError >
218224 where
219225 T : rosidl_runtime_rs:: Service ,
220226 F : Fn ( & rmw_request_id_t , T :: Request ) -> T :: Response + ' static + Send ,
221227 {
222- Service :: < T > :: new ( self , topic, callback)
228+ let service = Arc :: new ( crate :: node:: service:: Service :: < T > :: new (
229+ self , topic, callback,
230+ ) ?) ;
231+ self . services
232+ . push ( Arc :: downgrade ( & service) as Weak < dyn ServiceBase > ) ;
233+ Ok ( service)
223234 }
224235
225236 /// Creates a [`Subscription`][1].
@@ -236,7 +247,10 @@ impl Node {
236247 T : Message ,
237248 F : FnMut ( T ) + ' static + Send ,
238249 {
239- Subscription :: new ( self , topic, qos, callback)
250+ let subscription = Arc :: new ( Subscription :: < T > :: new ( self , topic, qos, callback) ?) ;
251+ self . subscriptions
252+ . push ( Arc :: downgrade ( & subscription) as Weak < dyn SubscriptionBase > ) ;
253+ Ok ( subscription)
240254 }
241255
242256 /// Returns the subscriptions that have not been dropped yet.
0 commit comments