Use new values api (#521)

This commit is contained in:
Nikolay Kim 2025-03-13 17:42:59 +05:00 committed by GitHub
parent cfc32ed74f
commit ab5fb624b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 55 additions and 79 deletions

View file

@ -45,7 +45,8 @@ ntex-util = { path = "ntex-util" }
ntex-compio = { path = "ntex-compio" } ntex-compio = { path = "ntex-compio" }
ntex-tokio = { path = "ntex-tokio" } ntex-tokio = { path = "ntex-tokio" }
ntex-neon = { git = "https://github.com/ntex-rs/neon.git" } #ntex-neon = { git = "https://github.com/ntex-rs/neon.git" }
#ntex-neon = { path = "../dev/neon" }
[workspace.dependencies] [workspace.dependencies]
async-task = "4.5.0" async-task = "4.5.0"

View file

@ -90,10 +90,7 @@ struct ConnectOpsInner {
impl ConnectOps { impl ConnectOps {
pub(crate) fn current() -> Self { pub(crate) fn current() -> Self {
Runtime::with_current(|rt| { Runtime::value(|rt| {
if let Some(s) = rt.get::<Self>() {
s
} else {
let mut inner = None; let mut inner = None;
rt.driver().register(|api| { rt.driver().register(|api| {
let ops = Rc::new(ConnectOpsInner { let ops = Rc::new(ConnectOpsInner {
@ -107,10 +104,7 @@ impl ConnectOps {
}) })
}); });
let s = ConnectOps(inner.unwrap()); ConnectOps(inner.unwrap())
rt.insert(s.clone());
s
}
}) })
} }

View file

@ -52,10 +52,7 @@ struct StreamOpsInner<T> {
impl<T: AsRawFd + 'static> StreamOps<T> { impl<T: AsRawFd + 'static> StreamOps<T> {
pub(crate) fn current() -> Self { pub(crate) fn current() -> Self {
Runtime::with_current(|rt| { Runtime::value(|rt| {
if let Some(s) = rt.get::<Self>() {
s
} else {
let mut inner = None; let mut inner = None;
rt.driver().register(|api| { rt.driver().register(|api| {
let ops = Rc::new(StreamOpsInner { let ops = Rc::new(StreamOpsInner {
@ -70,10 +67,7 @@ impl<T: AsRawFd + 'static> StreamOps<T> {
}) })
}); });
let s = StreamOps(inner.unwrap()); StreamOps(inner.unwrap())
rt.insert(s.clone());
s
}
}) })
} }

View file

@ -85,10 +85,7 @@ struct ConnectOpsInner {
impl ConnectOps { impl ConnectOps {
pub(crate) fn current() -> Self { pub(crate) fn current() -> Self {
Runtime::with_current(|rt| { Runtime::value(|rt| {
if let Some(s) = rt.get::<Self>() {
s
} else {
let mut inner = None; let mut inner = None;
rt.driver().register(|api| { rt.driver().register(|api| {
let ops = Rc::new(ConnectOpsInner { let ops = Rc::new(ConnectOpsInner {
@ -98,11 +95,7 @@ impl ConnectOps {
inner = Some(ops.clone()); inner = Some(ops.clone());
Box::new(ConnectOpsHandler { inner: ops }) Box::new(ConnectOpsHandler { inner: ops })
}); });
ConnectOps(inner.unwrap())
let s = ConnectOps(inner.unwrap());
rt.insert(s.clone());
s
}
}) })
} }

View file

@ -59,10 +59,7 @@ struct StreamOpsStorage<T> {
impl<T: AsRawFd + 'static> StreamOps<T> { impl<T: AsRawFd + 'static> StreamOps<T> {
pub(crate) fn current() -> Self { pub(crate) fn current() -> Self {
Runtime::with_current(|rt| { Runtime::value(|rt| {
if let Some(s) = rt.get::<Self>() {
s
} else {
let mut inner = None; let mut inner = None;
rt.driver().register(|api| { rt.driver().register(|api| {
let mut ops = Slab::new(); let mut ops = Slab::new();
@ -80,10 +77,7 @@ impl<T: AsRawFd + 'static> StreamOps<T> {
Box::new(StreamOpsHandler { inner: ops }) Box::new(StreamOpsHandler { inner: ops })
}); });
let s = StreamOps(inner.unwrap()); StreamOps(inner.unwrap())
rt.insert(s.clone());
s
}
}) })
} }