Commit 398aaa7 1 parent ffdc4ac commit 398aaa7 Copy full SHA for 398aaa7
File tree 2 files changed +24
-6
lines changed
2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,10 @@ impl Global {
79
79
self . 0 . write ( ) . await . register_instance ( handle) ;
80
80
}
81
81
82
+ pub async fn unregister_instance ( & self , id : i32 ) {
83
+ self . 0 . write ( ) . await . unregister_instance ( id) ;
84
+ }
85
+
82
86
pub async fn get_instance ( & self , id : i32 ) -> Option < InstanceHandle > {
83
87
self . 0 . read ( ) . await . instances . get ( & id) . cloned ( )
84
88
}
@@ -156,6 +160,14 @@ impl GlobalData {
156
160
}
157
161
158
162
fn register_instance ( & mut self , handle : InstanceHandle ) {
159
- self . instances . insert ( handle. id ( ) , handle) ;
163
+ let id = handle. id ( ) ;
164
+ self . instances . insert ( id, handle) ;
165
+ info ! ( "registered instance {}" , id) ;
166
+ }
167
+
168
+ fn unregister_instance ( & mut self , id : i32 ) {
169
+ if let Some ( _) = self . instances . remove ( & id) {
170
+ info ! ( "unregistered instance {}" , id) ;
171
+ }
160
172
}
161
173
}
Original file line number Diff line number Diff line change @@ -32,17 +32,23 @@ async fn run(opts: Opts) -> color_eyre::eyre::Result<()> {
32
32
let global = hyperion:: global:: GlobalData :: new ( & config) . wrap ( ) ;
33
33
34
34
// Initialize and spawn the devices
35
- for ( _ , inst) in & config. instances {
35
+ for ( & id , inst) in & config. instances {
36
36
// Create the instance
37
37
let ( inst, handle) = hyperion:: instance:: Instance :: new ( global. clone ( ) , inst. clone ( ) ) . await ;
38
38
// Register the instance globally using its handle
39
39
global. register_instance ( handle) . await ;
40
40
// Run the instance futures
41
- tokio:: spawn ( async move {
42
- let result = inst . run ( ) . await ;
41
+ tokio:: spawn ( {
42
+ let global = global . clone ( ) ;
43
43
44
- if let Err ( error) = result {
45
- error ! ( "Instance error: {:?}" , error) ;
44
+ async move {
45
+ let result = inst. run ( ) . await ;
46
+
47
+ if let Err ( error) = result {
48
+ error ! ( "Instance error: {:?}" , error) ;
49
+ }
50
+
51
+ global. unregister_instance ( id) . await ;
46
52
}
47
53
} ) ;
48
54
}
You can’t perform that action at this time.
0 commit comments