ntex-rs / ntex

framework for composable networking services
Apache License 2.0
1.84k stars 105 forks source link

Allow passing Tokio Handle on ntex-rt #336

Closed pavlospt closed 2 months ago

fafhrd91 commented 2 months ago

idea is right, but I would make "handle: Option", and added ".new_with_handle(..)" methods.

fafhrd91 commented 2 months ago

as I remember you can use Handle::new() instead of actual handle.

pavlospt commented 2 months ago

as I remember you can use Handle::new() instead of actual handle.

I wasn't able to find a Handle::new() 🤔

fafhrd91 commented 2 months ago

https://docs.rs/tokio/latest/tokio/runtime/struct.Handle.html#method.current

pavlospt commented 2 months ago

https://docs.rs/tokio/latest/tokio/runtime/struct.Handle.html#method.current

Indeed ::current() is what I use in tests. Maybe you mean something else?

fafhrd91 commented 2 months ago

use current(), and something like use_current_handle: bool in builder

pavlospt commented 2 months ago

I have some tests that take longer than 60s on Ntex-rt and they fail with timeout. I believe I have reached the peak of my understanding of how the underlying system works here 😛 If you have more hints or advice let me know :D

fafhrd91 commented 2 months ago

add env_logger::init() to your test and try to run it with RUST_LOG=trace

pavlospt commented 2 months ago

I have tried that and also tried debugging it. It seems that the other test is panicking because it cannot find a configured runtime and panics at: lib.rs#353. I am not sure how to enable tokio feature for this test and I am out of ideas :/

fafhrd91 commented 2 months ago

default behavior must be same as before, running with handler must be enabled explicitly

pavlospt commented 2 months ago

But if this is not enabled with a Cargo feature then how am I going to import Handle 🤔 ?

fafhrd91 commented 2 months ago

you can use try_current(), if it returns error then switch to old behavior

pavlospt commented 2 months ago

Handle though resides in tokio crate. So if tokio feature is not enabled then how will the library compile when it needs to

use tok_io::runtime::Handle;

🤔

fafhrd91 commented 2 months ago

mark import with feature or move it inside block that already marked with feature

pavlospt commented 2 months ago

Ok I am now thinking this issue is above my skills with the language 😛 Thank for your time and your explanations though 🙏🏻

fafhrd91 commented 2 months ago

I will take check what I can do next weekend

fafhrd91 commented 2 months ago

here is example how to use tokio https://github.com/ntex-rs/examples/blob/1a365350df3a9c904da5fbaa3b1e479fdb9191da/tokio/src/main.rs#L77