Skip to content

Commit

Permalink
Async fn in trait (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 authored Jan 7, 2024
1 parent ae46768 commit 2f5e921
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 281 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [0.5.0-b.0] - 2024-01-07

* Use "async fn" in trait for Service definition

## [0.4.4] - 2023-11-11

* Update ntex-io
Expand Down
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-h2"
version = "0.4.4"
version = "0.5.0-b.0"
license = "MIT"
authors = ["Nikolay Kim <[email protected]>"]
description = "An HTTP/2 client and server"
Expand All @@ -19,14 +19,14 @@ default = []
unstable = []

[dependencies]
ntex-connect = "0.3.2"
ntex-io = "0.3.6"
ntex-connect = "1.0.0-b.0"
ntex-io = "1.0.0-b.0"
ntex-http = "0.1.10"
ntex-bytes = "0.1.20"
ntex-bytes = "0.1.21"
ntex-codec = "0.6.2"
ntex-service = "1.2.7"
ntex-util = "0.3.2"
ntex-rt = "0.4.7"
ntex-service = "2.0.0-b.0"
ntex-util = "1.0.0-b.0"
ntex-rt = "0.4.10"

bitflags = "2.4"
fxhash = "0.2.1"
Expand All @@ -46,13 +46,13 @@ walkdir = "2.3.2"
serde = "1.0.0"
serde_json = "1.0.0"

ntex = { version = "0.7.6", features = ["openssl", "tokio"] }
ntex-tls = { version = "0.3.0", features = ["openssl"] }
ntex = { version = "1.0.0-b.0", features = ["openssl", "tokio"] }
ntex-tls = { version = "1.0.0-b.0", features = ["openssl"] }
openssl = "0.10"

# Examples
env_logger = { version = "0.10", default-features = false }
ntex-connect = { version = "0.3.2", features = ["openssl", "tokio"] }
ntex-connect = { version = "1.0.0-b.0", features = ["openssl", "tokio"] }

[patch.crates-io]
ntex-h2 = { path = "." }
2 changes: 1 addition & 1 deletion src/client/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl SimpleClient {
HandleService::new(storage.clone()),
);

let fut = IoDispatcher::with_config(
let fut = IoDispatcher::new(
io,
con.codec().clone(),
disp,
Expand Down
9 changes: 4 additions & 5 deletions src/client/stream.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::task::{Context, Poll};
use std::{cell::RefCell, collections::VecDeque, fmt, pin::Pin, rc::Rc};
use std::{cell::RefCell, collections::VecDeque, fmt, future::poll_fn, pin::Pin, rc::Rc};

use ntex_bytes::Bytes;
use ntex_http::HeaderMap;
use ntex_service::{Service, ServiceCtx};
use ntex_util::future::{poll_fn, Either, Ready};
use ntex_util::future::Either;
use ntex_util::{task::LocalWaker, HashMap, Stream as FutStream};

use crate::error::OperationError;
Expand Down Expand Up @@ -198,9 +198,8 @@ impl HandleService {
impl Service<Message> for HandleService {
type Response = ();
type Error = ();
type Future<'f> = Ready<(), ()>;

fn call<'a>(&'a self, msg: Message, _: ServiceCtx<'a, Self>) -> Self::Future<'a> {
async fn call(&self, msg: Message, _: ServiceCtx<'_, Self>) -> Result<(), ()> {
let id = msg.id();
if let Some(inflight) = self.0 .0.inflight.borrow_mut().get_mut(&id) {
let eof = match msg.kind() {
Expand All @@ -214,7 +213,7 @@ impl Service<Message> for HandleService {
}
inflight.push(msg);
}
Ready::Ok(())
Ok(())
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bitflags::bitflags! {
const DISCONNECT_WHEN_READY = 0b0000_1000;
const SECURE = 0b0001_0000;
const STREAM_REFUSED = 0b0010_0000;
const KA_TIMER = 0b0100_0000;
}
}

Expand Down Expand Up @@ -673,7 +674,7 @@ impl RecvHalfConnection {
}

pub(crate) fn recv_pong(&self, _: frame::Ping) {
self.0.io.stop_keepalive_timer();
self.0.io.stop_timer();
}

pub(crate) fn recv_go_away(
Expand Down
16 changes: 8 additions & 8 deletions src/default.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt;

use ntex_service::{Service, ServiceCtx, ServiceFactory};
use ntex_util::future::Ready;

use super::control::{ControlMessage, ControlResult};

Expand All @@ -14,21 +13,22 @@ impl<E: fmt::Debug + 'static> ServiceFactory<ControlMessage<E>> for DefaultContr
type Error = E;
type InitError = E;
type Service = DefaultControlService;
type Future<'f> = Ready<Self::Service, Self::InitError>;

fn create(&self, _: ()) -> Self::Future<'_> {
Ready::Ok(DefaultControlService)
async fn create(&self, _: ()) -> Result<Self::Service, Self::InitError> {
Ok(DefaultControlService)
}
}

impl<E: fmt::Debug + 'static> Service<ControlMessage<E>> for DefaultControlService {
type Response = ControlResult;
type Error = E;
type Future<'f> = Ready<Self::Response, Self::Error>;

#[inline]
fn call<'a>(&'a self, msg: ControlMessage<E>, _: ServiceCtx<'a, Self>) -> Self::Future<'a> {
async fn call(
&self,
msg: ControlMessage<E>,
_: ServiceCtx<'_, Self>,
) -> Result<Self::Response, Self::Error> {
log::trace!("Default control service is used: {:?}", msg);
Ready::Ok(msg.ack())
Ok(msg.ack())
}
}
Loading

0 comments on commit 2f5e921

Please sign in to comment.