@@ -46,13 +46,13 @@ impl<I, R> ResourcesMap<I, R> {
4646 pub async fn remove < C , F > ( & self , index : & I , cleanup : C ) -> Result < ( ) , Error >
4747 where
4848 I : Ord + Clone + fmt:: Display + fmt:: Debug ,
49- C : FnOnce ( Arc < R > ) -> F ,
49+ C : FnOnce ( R ) -> F ,
5050 F : Future < Output = Result < ( ) , Error > > ,
5151 {
5252 let mut map = self . map . lock ( ) . await ;
5353 if let Some ( arc) = map. remove ( index) {
54- wait_for_resources_drop ( index, arc. clone ( ) ) . await ;
55- cleanup ( arc ) . await ?; // run before the map unlock
54+ let resource = wait_for_resources_drop ( index, arc) . await ;
55+ cleanup ( resource ) . await ?;
5656 Ok ( ( ) )
5757 } else {
5858 Err ( Error :: UnknownResource ( format ! ( "{index}" ) ) )
@@ -65,22 +65,22 @@ impl<I, R> ResourcesMap<I, R> {
6565 {
6666 let mut map = self . map . lock ( ) . await ;
6767 while let Some ( ( task, resources) ) = map. pop_first ( ) {
68- wait_for_resources_drop ( & task, resources) . await ;
68+ let _resource = wait_for_resources_drop ( & task, resources) . await ;
6969 }
7070 Ok ( ( ) )
7171 }
7272}
7373
74- pub async fn wait_for_resources_drop < I , R > ( index : & I , mut arc : Arc < R > )
74+ pub async fn wait_for_resources_drop < I , R > ( index : & I , mut arc : Arc < R > ) -> R
7575where
7676 I : fmt:: Display ,
7777{
7878 loop {
7979 match Arc :: try_unwrap ( arc) {
80- Ok ( _resource ) => {
80+ Ok ( resource ) => {
8181 // do nothing
8282 // just drop
83- break ;
83+ return resource ;
8484 }
8585 Err ( a) => {
8686 arc = a;
0 commit comments