leontoeides / google_maps

An unofficial Google Maps Platform client library for the Rust programming language.
https://crates.io/crates/google_maps
Apache License 2.0
58 stars 24 forks source link

Cannot be used in async context, conflicts with parent runtime #3

Closed ysangkok closed 3 years ago

ysangkok commented 4 years ago

I am using this library from an async context, and it seems to break with the message:

thread 'tokio-runtime-worker' panicked at 'Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.'

I have worked around it using an additional thread to wrap the google_maps usage.

But really, shouldn't the library be modified to be able to be used in a context with an existing runtime?

I was thinking, maybe it would be possible to provide either an async API? Alternatively, google_maps could simply return a reqwest::RequestBuilder and let me execute the request with my own reqwest::Client, then I could pass the response back into this library.

Or maybe there is some other obvious solution I am missing?

Thanks for your efforts, it works fine so far!

victorct-pronto commented 4 years ago

Having the same problem here.

leontoeides commented 4 years ago

Thanks for the feedback and sharing your workaround.

I haven't done any async work in Rust yet so it's more likely I'm missing something than you. The library is really just a glorified library of structs so maybe it has something to do with using the blocking version of Reqwest?

I like your idea of having the option to execute your own HTTP GET request and sending back the results. I'm not a big fan of having Reqwest as a dependency.

It might be a week or two before I can look at this more closely.

yandexx commented 4 years ago

FYI I've encountered the same issue when using blocking Reqwest client, independently of google_maps. Might be an issue in Reqwest or tokio, which I intend to minimize and report.

headuck commented 4 years ago

I had this issue before, and had created an async fork of this project for my own use here. You may take reference from the approach.

Mause commented 3 years ago

@headuck do you have any plans to update it for tokio 1?

headuck commented 3 years ago

@Mause My fork is being used in a 0.2 environment with other crates which also depends on 0.2. Perhaps need to wait a little bit when the dependencies are updated.

Mause commented 3 years ago

@headuck no worries, I wound up using the compatibility crate and it worked with no issues