Merge pull request #423 from teloxide/dev

v0.5.1 merge procedure
This commit is contained in:
Hirrolot 2021-08-05 10:41:06 -07:00 committed by GitHub
commit 6b8e139a50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 14 deletions

View file

@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [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
### Added

View file

@ -1,6 +1,6 @@
[package]
name = "teloxide"
version = "0.5.0"
version = "0.5.1"
edition = "2018"
description = "An elegant Telegram bots framework for Rust"
repository = "https://github.com/teloxide/teloxide"
@ -42,6 +42,8 @@ rustls = ["teloxide-core/rustls"]
auto-send = ["teloxide-core/auto_send"]
throttle = ["teloxide-core/throttle"]
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.`,
# and for teloxide-core.
@ -60,11 +62,13 @@ full = [
"rustls",
"auto-send",
"throttle",
"cache-me"
"cache-me",
"trace-adaptor",
"erased",
]
[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-macros = { version = "0.4", optional = true }

View file

@ -113,10 +113,18 @@ where
loop {
tokio::signal::ctrl_c().await.expect("Failed to listen for ^C");
log::info!("^C received, trying to shutdown the dispatcher...");
// If dispatcher wasn't running, then there is nothing to do
shutdown_inner(&state).ok();
match shutdown_inner(&state) {
Ok(()) => log::info!("^C received, trying to shutdown the dispatcher..."),
Err(Ok(AlreadyShuttingDown)) => {
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
/// ignored.
pub fn shutdown(&self) -> Result<impl Future<Output = ()> + '_, IdleShutdownError> {
shutdown_inner(&self.dispatcher_state).map(|()| async move {
log::info!("Trying to shutdown the dispatcher...");
self.shutdown_notify_back.notified().await
})
match shutdown_inner(&self.dispatcher_state) {
Ok(()) | Err(Ok(AlreadyShuttingDown)) => Ok(async move {
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)
}
fn shutdown_inner(state: &DispatcherState) -> Result<(), IdleShutdownError> {
struct AlreadyShuttingDown;
fn shutdown_inner(
state: &DispatcherState,
) -> Result<(), Result<AlreadyShuttingDown, IdleShutdownError>> {
use ShutdownState::*;
let res = state.compare_exchange(Running, ShuttingDown);
match res {
Ok(_) | Err(ShuttingDown) => Ok(()),
Err(Idle) => Err(IdleShutdownError),
Ok(_) => Ok(()),
Err(ShuttingDown) => Err(Ok(AlreadyShuttingDown)),
Err(Idle) => Err(Err(IdleShutdownError)),
Err(Running) => unreachable!(),
}
}