MCPcopy Create free account
hub / github.com/Botloader/botloader / handle_cmd

Method handle_cmd

components/vm/src/vm.rs:263–314  ·  view source on GitHub ↗
(&mut self, cmd: VmCommand)

Source from the content-addressed store, hash-verified

261 }
262
263 async fn handle_cmd(&mut self, cmd: VmCommand) {
264 match cmd {
265 VmCommand::Restart(new_scripts) => {
266 self.restart(new_scripts).await;
267 }
268 VmCommand::DispatchEvent(dispatch_event) => self.dispatch_event(dispatch_event),
269 VmCommand::LoadScript(script) => {
270 if let Some(script) = self.compile_script(script) {
271 self.run_script(script.script.id).await
272 }
273 }
274 VmCommand::UpdateScript(script) => {
275 let mut cloned_scripts = self
276 .script_store
277 .borrow()
278 .scripts
279 .iter()
280 .map(|v| v.script.clone())
281 .collect::<Vec<_>>();
282
283 let mut need_reset = false;
284 for old in &mut cloned_scripts {
285 if old.id == script.id {
286 *old = script.clone();
287 need_reset = true;
288 }
289 }
290
291 if need_reset {
292 self.restart(cloned_scripts).await;
293 }
294 }
295 VmCommand::UnloadScripts(scripts) => {
296 let new_scripts = self
297 .script_store
298 .borrow()
299 .scripts
300 .iter()
301 .filter_map(|sc| {
302 if !scripts.iter().any(|isc| isc.id == sc.script.id) {
303 Some(sc.script.clone())
304 } else {
305 None
306 }
307 })
308 .collect::<Vec<_>>();
309
310 self.restart(new_scripts).await;
311 }
312 };
313 // self._dump_heap_stats();
314 }
315
316 #[instrument(skip_all, fields(num_scripts=scripts.len()))]
317 fn compile_scripts(&self, scripts: &Vec<Script>) {

Callers 1

runMethod · 0.45

Calls 4

restartMethod · 0.80
dispatch_eventMethod · 0.80
compile_scriptMethod · 0.80
run_scriptMethod · 0.80

Tested by

no test coverage detected