diff --git a/Cargo.toml b/Cargo.toml index 33c4258..5616a9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,15 @@ documentation = "https://docs.rs/delay_timer" readme = "README.md" homepage = "https://github.com/BinChengZhao/delay-timer" description = "Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible, and dynamic add/cancel/remove is supported." -keywords = [ "cron", "scheduler", "timer", "crontab", "delay" ] +keywords = ["cron", "scheduler", "timer", "crontab", "delay"] license = "Apache-2.0 OR MIT" -categories = ["development-tools", "data-structures", "asynchronous", "data-structures", "accessibility"] +categories = [ + "development-tools", + "data-structures", + "asynchronous", + "data-structures", + "accessibility", +] build = "build/build.rs" @@ -30,14 +36,14 @@ status-report = [] cron_clock = "0.8.0" anyhow = "^1.0.31" rs-snowflake = "0.6.0" -dashmap = "=5.5.3" +dashmap = "6" lru = "0.12.3" once_cell = "1.9.0" futures = "^0.3.13" -smol = "^1.2.5" +smol = "2" concat-idents = "1.1.3" async-trait = "^0.1.48" -event-listener = "=5.3.0" +event-listener = "5" log = "0.4.14" tracing = "0.1.29" thiserror = "^1.0.24" @@ -46,19 +52,21 @@ thiserror = "^1.0.24" tokio = { version = "^1.3.0", features = ["full"] } [dev-dependencies] -rand = "0.8.4" +rand = "0.8.5" surf = "^2.1.0" -tracing-error = { version = "0.1.2" } -tracing-subscriber = "0.2.0" +tracing-error = { version = "0.2" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tokio = { version = "^1.3.0", features = ["full"] } -hyper= {version = "^0.14.2" , features = ["full"] } -pretty_env_logger = "^0.4" -mockall = "^0.8.2" -env_logger = "^0.8.3" -color-eyre = { version = "0.5.11", features = ["capture-spantrace", "issue-url"]} -pretty_assertions = "0.6.1" +hyper = { version = "1.4", features = ["full"] } +hyper-util = { version = "0.1", features = ["full"] } +http-body-util = "0.1.2" +pretty_env_logger = "0.5" +mockall = "^0.13" +env_logger = "^0.11.5" +color-eyre = { version = "0.6", features = ["capture-spantrace", "issue-url"] } +pretty_assertions = "1.4.1" thiserror = "1.0.19" -ansi-parser = "0.6.5" # used for testing color schemes +ansi-parser = "0.9.1" # used for testing color schemes [dev-dependencies.async-std] version = "^1.9.0" @@ -66,7 +74,7 @@ features = ["attributes", "unstable"] [build-dependencies] autocfg = "1" -rustc_version = "^0.2" +rustc_version = "0.4" # Append the cfg-tag:docsrs to activate the feature(doc_cfg) attribute # when generating a document on docs.rs. @@ -89,6 +97,12 @@ name = "demo" path = "examples/demo.rs" required-features = ["full"] +[[example]] +name = "generic" +path = "examples/generic.rs" +required-features = ["full"] + + #[[test]] #name = "inspect_struct" #path = "tests/simulation.rs" @@ -100,4 +114,4 @@ required-features = ["full"] #required-features = ["full"] [profile.dev.package.backtrace] -opt-level = 3 \ No newline at end of file +opt-level = 3 diff --git a/README.md b/README.md index f6859e8..e225fd9 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,10 @@ fn build_task_async_print() -> Result { ``` rust #[macro_use] use delay_timer::prelude::*; - use hyper::{Client, Uri}; + use http_body_util::{BodyExt, Empty}; + use hyper::{body::Bytes, Uri}; + use hyper_util::{client::legacy::Client, rt::TokioExecutor}; + fn build_task_customized_async_task() -> Result { let id = 1; diff --git a/examples/cycle_tokio_task.rs b/examples/cycle_tokio_task.rs index 2a04457..324cfc8 100644 --- a/examples/cycle_tokio_task.rs +++ b/examples/cycle_tokio_task.rs @@ -2,7 +2,9 @@ use anyhow::Result; use delay_timer::prelude::*; -use hyper::{Client, Uri}; +use http_body_util::{BodyExt, Empty}; +use hyper::{body::Bytes, Uri}; +use hyper_util::{client::legacy::Client, rt::TokioExecutor}; use std::thread::{current, park, Thread}; // When you try to run that's example nedd add feature `tokio-support`. @@ -62,7 +64,7 @@ pub async fn generate_closure_template() { } pub async fn async_template(id: i32, name: String) -> Result<()> { - let client = Client::new(); + let client = Client::builder(TokioExecutor::new()).build_http::>(); // The default connector does not handle TLS. // Speaking to https destinations will require configuring a connector that implements TLS. @@ -73,7 +75,7 @@ pub async fn async_template(id: i32, name: String) -> Result<()> { let res = client.get(uri).await?; println!("Response: {}", res.status()); // Concatenate the body stream into a single buffer... - let buf = hyper::body::to_bytes(res).await?; + let buf = res.into_body().collect().await?.to_bytes(); println!("body: {buf:?}"); Ok(()) } diff --git a/examples/demo_async_tokio.rs b/examples/demo_async_tokio.rs index 315a8b7..2c8fd02 100644 --- a/examples/demo_async_tokio.rs +++ b/examples/demo_async_tokio.rs @@ -2,7 +2,12 @@ use anyhow::Result; use delay_timer::prelude::*; #[allow(deprecated)] use delay_timer::utils::convenience::functions::unblock_process_task_fn; -use hyper::{Client, Uri}; +use http_body_util::{combinators::BoxBody, BodyExt, Empty}; +use hyper::{ + body::{Body, Bytes}, + Uri, +}; +use hyper_util::{client::legacy::Client, rt::TokioExecutor}; use std::time::Duration; use tokio::time::sleep; use tracing::Level; @@ -95,7 +100,7 @@ fn build_task_async_execute_process() -> Result { } pub async fn async_template(id: i32, name: String) -> Result<()> { - let client = Client::new(); + let client = Client::builder(TokioExecutor::new()).build_http::>(); // The default connector does not handle TLS. // Speaking to https destinations will require configuring a connector that implements TLS. @@ -106,7 +111,7 @@ pub async fn async_template(id: i32, name: String) -> Result<()> { let res = client.get(uri).await?; println!("Response: {}", res.status()); // Concatenate the body stream into a single buffer... - let buf = hyper::body::to_bytes(res).await?; + let buf = res.into_body().collect().await?.to_bytes(); println!("body: {buf:?}"); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 3ce9a5a..33d7257 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -192,7 +192,9 @@ //! use std::time::Duration; //! use smol::Timer; //! use tokio::time::sleep; -//! use hyper::{Client, Uri}; +//! use http_body_util::{BodyExt, Empty}; +//! use hyper::{body::Bytes, Uri}; +//! use hyper_util::{client::legacy::Client, rt::TokioExecutor}; //! //! //! @@ -217,7 +219,7 @@ //! //! //! pub async fn async_template(id: i32, name: String) -> Result<()> { -//! let client = Client::new(); +//! let client = Client::builder(TokioExecutor::new()).build_http::>(); //! //! // The default connector does not handle TLS. //! // Speaking to https destinations will require configuring a connector that implements TLS. @@ -228,7 +230,7 @@ //! let res = client.get(uri).await?; //! println!("Response: {}", res.status()); //! // Concatenate the body stream into a single buffer... -//! let buf = hyper::body::to_bytes(res).await?; +//! let buf = res.into_body().collect().await?.to_bytes(); //! println!("body: {:?}", buf); //! Ok(()) //! } diff --git a/src/timer/task.rs b/src/timer/task.rs index 4f5fe1e..88dd294 100644 --- a/src/timer/task.rs +++ b/src/timer/task.rs @@ -204,7 +204,7 @@ pub(crate) enum FrequencyInner { SecondsCountDown(u64, SecondsState), } -impl<'a> TryFrom<(FrequencyUnify<'a>, ScheduleIteratorTimeZone)> for FrequencyInner { +impl TryFrom<(FrequencyUnify<'_>, ScheduleIteratorTimeZone)> for FrequencyInner { type Error = FrequencyAnalyzeError; fn try_from( @@ -385,9 +385,8 @@ impl DelayTimerScheduleIteratorOwned { let new_result = DelayTimerScheduleIteratorOwned::new(schedule_iterator_time_zone_query.clone()); - new_result.map(|task_schedule| { + new_result.inspect(|task_schedule| { lru_cache.put(schedule_iterator_time_zone_query, task_schedule.clone()); - task_schedule }) })?; diff --git a/src/utils/convenience.rs b/src/utils/convenience.rs index 1c550fe..29b6c71 100644 --- a/src/utils/convenience.rs +++ b/src/utils/convenience.rs @@ -103,7 +103,7 @@ pub mod functions { #[inline(always)] ///convert task_handler of impl DelayTaskHandler to a `Box`. pub fn create_delay_task_handler( - task_handle: impl DelayTaskHandler + 'static + Send + Sync, + task_handle: impl DelayTaskHandler + 'static, ) -> Box { Box::new(task_handle) as Box }