(
&mut self,
command: &ExtensionCommand,
tx: MainCommandReplySender,
)
| 632 | |
| 633 | #[tracing::instrument(level = "debug", skip(self))] |
| 634 | async fn execute_command( |
| 635 | &mut self, |
| 636 | command: &ExtensionCommand, |
| 637 | tx: MainCommandReplySender, |
| 638 | ) -> MoosyncResult<()> { |
| 639 | let (package_name, fn_name, args) = command.to_plugin_call(); |
| 640 | let plugins = self.get_extensions(package_name.clone()).await; |
| 641 | |
| 642 | let plugins_len = plugins.len(); |
| 643 | |
| 644 | for extension in plugins { |
| 645 | let command = command.clone(); |
| 646 | let args = args.clone(); |
| 647 | let extension = extension.clone(); |
| 648 | let package_name = package_name.clone(); |
| 649 | let tx = tx.clone(); |
| 650 | thread::spawn(move || { |
| 651 | let mut plugin = block_on(extension.plugin.lock()); |
| 652 | let res = plugin.call::<_, Value>(fn_name, args.clone()); |
| 653 | match res { |
| 654 | Ok(res) => match command.parse_response(res) { |
| 655 | Ok(mut parsed_response) => { |
| 656 | Self::sanitize_response(&mut parsed_response, package_name.clone()); |
| 657 | if plugins_len == 1 { |
| 658 | let _ = tx.send(parsed_response); |
| 659 | } |
| 660 | } |
| 661 | Err(e) => { |
| 662 | if plugins_len == 1 { |
| 663 | let _ = tx.send(ExtensionCommandResponse::Empty); |
| 664 | tracing::error!( |
| 665 | "Failed to parse response from extension {} {:?}", |
| 666 | package_name, |
| 667 | e |
| 668 | ); |
| 669 | } |
| 670 | } |
| 671 | }, |
| 672 | Err(e) => { |
| 673 | if plugins_len == 1 { |
| 674 | let _ = tx.send(ExtensionCommandResponse::Empty); |
| 675 | tracing::error!( |
| 676 | "Extension {} responsed with error: {:?}", |
| 677 | extension.package_name, |
| 678 | e |
| 679 | ); |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | }); |
| 684 | } |
| 685 | |
| 686 | if plugins_len > 1 { |
| 687 | let _ = tx.send(ExtensionCommandResponse::Empty); |
| 688 | } |
| 689 | Ok(()) |
| 690 | } |
| 691 |
no test coverage detected