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

Async support #23

Open
Bauxitedev opened this issue Feb 13, 2023 · 2 comments
Open

Async support #23

Bauxitedev opened this issue Feb 13, 2023 · 2 comments

Comments

@Bauxitedev
Copy link

Does this crate support async? If not, how would I go about using this in an async context? (e.g. for a file upload in an async web server)

@Roughsketch
Copy link
Owner

It does not support async internally and probably won't in the near future.

One goal of this library is to have zero dependencies, and from a quick glance all the async io examples I see use other crates. I'm not saying it'll never happen, but it looks like it'll increase the complexity of the library quite a bit.

As for your file upload example I don't have any specific help to give you, but I do use this crate in an async context via Serenity with no issues. I don't do anything special, I just call it from inside an async function and the library handles execution.

@Bauxitedev
Copy link
Author

Bauxitedev commented Feb 20, 2023

I see. For anyone else looking for async support, this is the workaround I managed to come up with. file is a tokio::fs::File.

let std_file = file.try_clone().await?.into_std().await;
let imgsize = spawn_blocking(|| {
    imagesize::reader_size(std::io::BufReader::new(std_file))
})
.await
.expect("Panic occured while trying to infer image size")?;

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

No branches or pull requests

2 participants