Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can runtime arguments be made optional? #977

Closed
dfoxfranke opened this issue Dec 29, 2019 · 6 comments
Closed

Can runtime arguments be made optional? #977

dfoxfranke opened this issue Dec 29, 2019 · 6 comments

Comments

@dfoxfranke
Copy link

dfoxfranke commented Dec 29, 2019

Having to pass a tokio::runtime::Handle in order to construct an AsyncResolver (or a TokioConnectionProvider) is slightly awkward because it means that programs which use AsyncResolver can't be written with a main function declared using #[tokio::main]. Programs which use #[tokio::main] never explicitly construct a tokio runtime and have no means of obtaining a handle to the one that tokio implicitly constructs. Could the runtime argument be made Optional, such that if None is passed then the resolver will just spawn tasks on the default executor using tokio::spawn()?

@bluejekyll
Copy link
Member

I'd consider it. I hate relying on thread local storage for this stuff, it makes testing really difficult. Let me review our options in this area.

It might be that we could pass in a TokioTlsHandle that carries no data, and just calls tokio::spawn. I think that would be fine. And that could be the default you're looking for.

@bluejekyll
Copy link
Member

bluejekyll commented Dec 30, 2019

Ok, I think we're going to handle this in the tokio library itself: tokio-rs/tokio#2040

Once that or something like it lands, we can then have a default method on trust-dns-resolver then takes the thread-local instantiated Handle, which will work in this case.

@bluejekyll
Copy link
Member

FYI, with https://docs.rs/tokio/0.2.8/tokio/runtime/struct.Handle.html#method.current now in Tokio, users should be able to get a handle to the current runtime in a #[tokio::main]. I'll add a function for initializing trust-dns-resolver so that the extra code isn't necessary.

@gzbakku
Copy link

gzbakku commented Oct 25, 2020

has this problem been resolved
how to do this??

@djc
Copy link
Collaborator

djc commented Oct 26, 2020

I think this has been solved? At least you can in 0.19 instantiate a TokioAsyncResolver that doesn't require you to pass in a Handle.

@dfoxfranke
Copy link
Author

Yes, this should be closed with the addition of the tokio_from_system_conf() constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants