Cleanly shutdown on ctrl_c
Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
f90b152abf
commit
e064263f96
3 changed files with 54 additions and 22 deletions
11
src/bot.rs
11
src/bot.rs
|
|
@ -14,9 +14,10 @@
|
|||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::hooks::{format_hook, Hook};
|
||||
use crate::Error;
|
||||
|
||||
use log::debug;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::{signal::ctrl_c, sync::mpsc};
|
||||
use xmpp::jid::{BareJid, Jid, ResourcePart};
|
||||
use xmpp::parsers::message::MessageType;
|
||||
use xmpp::{
|
||||
|
|
@ -85,6 +86,9 @@ impl XmppClient {
|
|||
pub async fn receive(&mut self, mut rx: mpsc::UnboundedReceiver<Hook>) {
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = ctrl_c() => {
|
||||
return; // Disconnecting
|
||||
},
|
||||
_ = self.next() => (),
|
||||
wh = rx.recv() => {
|
||||
if let Some(hook) = wh {
|
||||
|
|
@ -114,4 +118,9 @@ impl XmppClient {
|
|||
debug!("XMPP Bot Processed Hook");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn disconnect(self) -> Result<(), Error> {
|
||||
log::info!("Disconnecting...");
|
||||
Ok(self.agent.disconnect().await?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue