create the ctrlc handler directly around the PluginInterface and stash the guard on RunningPlugin

this looks much better
will back out the changes to PluginGc
This commit is contained in:
Andy Gayton 2024-06-22 06:12:49 -04:00
parent e194218169
commit 34acc251ff
2 changed files with 14 additions and 1 deletions

View File

@ -50,6 +50,8 @@ struct RunningPlugin {
interface: PluginInterface, interface: PluginInterface,
/// Garbage collector for the plugin /// Garbage collector for the plugin
gc: PluginGc, gc: PluginGc,
/// todo: docs
_ctrlc_guard: Option<ctrlc::Guard>,
} }
impl PersistentPlugin { impl PersistentPlugin {
@ -212,7 +214,14 @@ impl PersistentPlugin {
return self.spawn(envs, mutable, ctrlc_handlers); return self.spawn(envs, mutable, ctrlc_handlers);
} }
mutable.running = Some(RunningPlugin { interface, gc }); let guard = ctrlc_handlers.map(|ctrlc_handlers| {
let interface = interface.clone();
ctrlc_handlers.add(Box::new(move || {
let _ = interface.ctrlc();
}))
});
mutable.running = Some(RunningPlugin { interface, gc, _ctrlc_guard: guard});
Ok(()) Ok(())
} }

View File

@ -322,6 +322,10 @@ impl InterfaceManager for EngineInterfaceManager {
}); });
self.send_engine_call_response(id, response) self.send_engine_call_response(id, response)
} }
PluginInput::Ctrlc => {
eprintln!("Received Ctrl-C!");
Ok(())
}
} }
} }