mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 21:07:39 +03:00
Use async fn for Service::ready() and Service::shutdown() (#363)
This commit is contained in:
parent
dec6ab083a
commit
b04bdf41f6
33 changed files with 285 additions and 299 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [2.0.0] - 2024-05-28
|
||||
|
||||
* Use async fn for Service::ready() and Service::shutdown()
|
||||
|
||||
## [1.0.2] - 2024-03-30
|
||||
|
||||
* Fix glommio compat feature #327
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-net"
|
||||
version = "1.0.2"
|
||||
version = "2.0.0"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "ntexwork utils for ntex framework"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
@ -28,16 +28,16 @@ glommio = ["ntex-rt/glommio", "ntex-glommio"]
|
|||
async-std = ["ntex-rt/async-std", "ntex-async-std"]
|
||||
|
||||
[dependencies]
|
||||
ntex-service = "2.0"
|
||||
ntex-bytes = "0.1.24"
|
||||
ntex-service = "3.0"
|
||||
ntex-bytes = "0.1"
|
||||
ntex-http = "0.1"
|
||||
ntex-io = "1.0"
|
||||
ntex-io = "2.0"
|
||||
ntex-rt = "0.4.11"
|
||||
ntex-util = "1.0"
|
||||
ntex-util = "2.0"
|
||||
|
||||
ntex-tokio = { version = "0.4.0", optional = true }
|
||||
ntex-glommio = { version = "0.4.0", optional = true }
|
||||
ntex-async-std = { version = "0.4.0", optional = true }
|
||||
ntex-tokio = { version = "0.5.0", optional = true }
|
||||
ntex-glommio = { version = "0.5.0", optional = true }
|
||||
ntex-async-std = { version = "0.5.0", optional = true }
|
||||
|
||||
log = "0.4"
|
||||
thiserror = "1.0"
|
||||
|
|
|
@ -6,7 +6,6 @@ use ntex_util::future::Either;
|
|||
|
||||
use super::{Address, Connect, ConnectError};
|
||||
|
||||
#[derive(Copy)]
|
||||
/// DNS Resolver Service
|
||||
pub struct Resolver<T>(marker::PhantomData<T>);
|
||||
|
||||
|
@ -17,6 +16,8 @@ impl<T> Resolver<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Copy for Resolver<T> {}
|
||||
|
||||
impl<T: Address> Resolver<T> {
|
||||
/// Lookup ip addresses for provided host
|
||||
pub async fn lookup(&self, req: Connect<T>) -> Result<Connect<T>, ConnectError> {
|
||||
|
@ -100,7 +101,7 @@ impl<T> Default for Resolver<T> {
|
|||
|
||||
impl<T> Clone for Resolver<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Resolver(marker::PhantomData)
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +118,7 @@ impl<T: Address, C> ServiceFactory<Connect<T>, C> for Resolver<T> {
|
|||
type InitError = ();
|
||||
|
||||
async fn create(&self, _: C) -> Result<Self::Service, Self::InitError> {
|
||||
Ok(self.clone())
|
||||
Ok(*self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +145,7 @@ mod tests {
|
|||
async fn resolver() {
|
||||
let resolver = Resolver::default().clone();
|
||||
assert!(format!("{:?}", resolver).contains("Resolver"));
|
||||
let srv = resolver.pipeline(()).await.unwrap();
|
||||
let srv = resolver.pipeline(()).await.unwrap().bind();
|
||||
assert!(lazy(|cx| srv.poll_ready(cx)).await.is_ready());
|
||||
|
||||
let res = srv.call(Connect::new("www.rust-lang.org")).await;
|
||||
|
|
|
@ -9,13 +9,15 @@ use ntex_util::future::{BoxFuture, Either};
|
|||
use super::{Address, Connect, ConnectError, Resolver};
|
||||
use crate::tcp_connect_in;
|
||||
|
||||
#[derive(Copy)]
|
||||
/// Basic tcp stream connector
|
||||
pub struct Connector<T> {
|
||||
resolver: Resolver<T>,
|
||||
pool: PoolRef,
|
||||
tag: &'static str,
|
||||
}
|
||||
|
||||
impl<T> Copy for Connector<T> {}
|
||||
|
||||
impl<T> Connector<T> {
|
||||
/// Construct new connect service with default dns resolver
|
||||
pub fn new() -> Self {
|
||||
|
@ -85,11 +87,7 @@ impl<T> Default for Connector<T> {
|
|||
|
||||
impl<T> Clone for Connector<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Connector {
|
||||
resolver: self.resolver.clone(),
|
||||
tag: self.tag,
|
||||
pool: self.pool,
|
||||
}
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +108,7 @@ impl<T: Address, C> ServiceFactory<Connect<T>, C> for Connector<T> {
|
|||
type InitError = ();
|
||||
|
||||
async fn create(&self, _: C) -> Result<Self::Service, Self::InitError> {
|
||||
Ok(self.clone())
|
||||
Ok(*self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue