use super::Router;
use crate::channel_types::SmallSender;
use crate::{
error::{NodeError, NodeReason},
NodeReplyResult, RouterReply,
};
use ockam_core::{Address, Result};
pub(super) async fn exec(
router: &mut Router,
main_addr: &Address,
reply: &SmallSender<NodeReplyResult>,
) -> Result<()> {
trace!("Stopping processor '{}'", main_addr);
let mut record = match router.map.remove_address_record(main_addr) {
Some(proc) => proc,
None => {
reply
.send(RouterReply::no_such_address(main_addr.clone()))
.await
.map_err(|_| NodeError::NodeState(NodeReason::Unknown).internal())?;
return Ok(());
}
};
router.map.remove_alias(main_addr);
record.stop().await?;
reply
.send(RouterReply::ok())
.await
.map_err(|_| NodeError::NodeState(NodeReason::Unknown).internal())?;
Ok(())
}