mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +01:00
commit
6b8e139a50
3 changed files with 40 additions and 14 deletions
|
@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [unreleased]
|
## [unreleased]
|
||||||
|
|
||||||
|
## [0.5.1] - 2021-08-05
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Improved log messages when `^C` is received with `^C` handler set up
|
||||||
|
|
||||||
## [0.5.0] - 2021-07-08
|
## [0.5.0] - 2021-07-08
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "teloxide"
|
name = "teloxide"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "An elegant Telegram bots framework for Rust"
|
description = "An elegant Telegram bots framework for Rust"
|
||||||
repository = "https://github.com/teloxide/teloxide"
|
repository = "https://github.com/teloxide/teloxide"
|
||||||
|
@ -42,6 +42,8 @@ rustls = ["teloxide-core/rustls"]
|
||||||
auto-send = ["teloxide-core/auto_send"]
|
auto-send = ["teloxide-core/auto_send"]
|
||||||
throttle = ["teloxide-core/throttle"]
|
throttle = ["teloxide-core/throttle"]
|
||||||
cache-me = ["teloxide-core/cache_me"]
|
cache-me = ["teloxide-core/cache_me"]
|
||||||
|
trace-adaptor = ["teloxide-core/trace_adaptor"]
|
||||||
|
erased = ["teloxide-core/erased"]
|
||||||
|
|
||||||
# currently used for `README.md` tests, building docs for `docsrs` to add `This is supported on feature="..." only.`,
|
# currently used for `README.md` tests, building docs for `docsrs` to add `This is supported on feature="..." only.`,
|
||||||
# and for teloxide-core.
|
# and for teloxide-core.
|
||||||
|
@ -60,11 +62,13 @@ full = [
|
||||||
"rustls",
|
"rustls",
|
||||||
"auto-send",
|
"auto-send",
|
||||||
"throttle",
|
"throttle",
|
||||||
"cache-me"
|
"cache-me",
|
||||||
|
"trace-adaptor",
|
||||||
|
"erased",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
teloxide-core = { version = "0.3.1", default-features = false }
|
teloxide-core = { version = "0.3.3", default-features = false }
|
||||||
#teloxide-core = { git = "https://github.com/teloxide/teloxide-core.git", rev = "...", default-features = false }
|
#teloxide-core = { git = "https://github.com/teloxide/teloxide-core.git", rev = "...", default-features = false }
|
||||||
teloxide-macros = { version = "0.4", optional = true }
|
teloxide-macros = { version = "0.4", optional = true }
|
||||||
|
|
||||||
|
|
|
@ -113,10 +113,18 @@ where
|
||||||
loop {
|
loop {
|
||||||
tokio::signal::ctrl_c().await.expect("Failed to listen for ^C");
|
tokio::signal::ctrl_c().await.expect("Failed to listen for ^C");
|
||||||
|
|
||||||
log::info!("^C received, trying to shutdown the dispatcher...");
|
match shutdown_inner(&state) {
|
||||||
|
Ok(()) => log::info!("^C received, trying to shutdown the dispatcher..."),
|
||||||
// If dispatcher wasn't running, then there is nothing to do
|
Err(Ok(AlreadyShuttingDown)) => {
|
||||||
shutdown_inner(&state).ok();
|
log::info!(
|
||||||
|
"^C received, the dispatcher is already shutting down, ignoring the \
|
||||||
|
signal"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Err(Err(IdleShutdownError)) => {
|
||||||
|
log::info!("^C received, the dispatcher isn't running, ignoring the signal")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -546,10 +554,13 @@ impl ShutdownToken {
|
||||||
/// If you don't need to wait for shutdown, the returned future can be
|
/// If you don't need to wait for shutdown, the returned future can be
|
||||||
/// ignored.
|
/// ignored.
|
||||||
pub fn shutdown(&self) -> Result<impl Future<Output = ()> + '_, IdleShutdownError> {
|
pub fn shutdown(&self) -> Result<impl Future<Output = ()> + '_, IdleShutdownError> {
|
||||||
shutdown_inner(&self.dispatcher_state).map(|()| async move {
|
match shutdown_inner(&self.dispatcher_state) {
|
||||||
log::info!("Trying to shutdown the dispatcher...");
|
Ok(()) | Err(Ok(AlreadyShuttingDown)) => Ok(async move {
|
||||||
self.shutdown_notify_back.notified().await
|
log::info!("Trying to shutdown the dispatcher...");
|
||||||
})
|
self.shutdown_notify_back.notified().await
|
||||||
|
}),
|
||||||
|
Err(Err(err)) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,14 +630,19 @@ fn shutdown_check_timeout_for<E>(update_listener: &impl UpdateListener<E>) -> Du
|
||||||
shutdown_check_timeout.checked_add(MIN_SHUTDOWN_CHECK_TIMEOUT).unwrap_or(shutdown_check_timeout)
|
shutdown_check_timeout.checked_add(MIN_SHUTDOWN_CHECK_TIMEOUT).unwrap_or(shutdown_check_timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shutdown_inner(state: &DispatcherState) -> Result<(), IdleShutdownError> {
|
struct AlreadyShuttingDown;
|
||||||
|
|
||||||
|
fn shutdown_inner(
|
||||||
|
state: &DispatcherState,
|
||||||
|
) -> Result<(), Result<AlreadyShuttingDown, IdleShutdownError>> {
|
||||||
use ShutdownState::*;
|
use ShutdownState::*;
|
||||||
|
|
||||||
let res = state.compare_exchange(Running, ShuttingDown);
|
let res = state.compare_exchange(Running, ShuttingDown);
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(_) | Err(ShuttingDown) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(Idle) => Err(IdleShutdownError),
|
Err(ShuttingDown) => Err(Ok(AlreadyShuttingDown)),
|
||||||
|
Err(Idle) => Err(Err(IdleShutdownError)),
|
||||||
Err(Running) => unreachable!(),
|
Err(Running) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue