rust-lang / wg-async

Working group dedicated to improving the foundations of Async I/O in Rust
https://rust-lang.github.io/wg-async/
Apache License 2.0
379 stars 88 forks source link

Migrating an existing sync crate to async #157

Open alsuren opened 3 years ago

alsuren commented 3 years ago

Brief summary

Reasons for needing to do this include:

I know of multiple examples of projects that have done this in the recent-ish past. I will write them down in the "characters" section, and if anyone wants me to add links to issues/pull-requests or @mention the relevant parties to give more insights then I will.

I probably don't have the brain-space to write this up properly myself, but it came up in one of the writing sessions that I attended, and I put something on my todo list to make a ticket about it, so this is my attempt at clearing my backlog.

It is also mentioned in https://github.com/rust-lang/wg-async-foundations/issues/98, to that issue description should be updated now that this ticket exits. 😀

Optional details

pickfire commented 3 years ago

What about async back to sync? Is it possible?

ar37-rs commented 3 years ago

What about async back to sync? Is it possible?

if you only need simple fetching request, you can mix them: https://github.com/Ar37-rs/asynchron/blob/main/example/fltk_fetch/src/main.rs

pickfire commented 3 years ago

@Ar37-rs I think you mistake what I was mentioning. I was talking about that with regard to migrating existing sync crate to async. Although some crate may start by creating an async crate, but if someone wants a sync API, is there a low effort way of doing so?

Yes, one could use block_on but it would be simpler with reqwest::blocking. This could overlap with https://github.com/rust-lang/wg-async-foundations/issues/54 but sometimes the author already know blocking is alright but some crates such as surf are designed with async in the first place, so the only method for it is block_on, so is there a simpler way to get a sync API?

ar37-rs commented 3 years ago

@Ar37-rs I think you mistake what I was mentioning. I was talking about that with regard to migrating existing sync crate to async. Although some crate may start by creating an async crate, but if someone wants a sync API, is there a low effort way of doing so?

Yes, one could use block_on but it would be simpler with reqwest::blocking. This could overlap with #54 but sometimes the author already know blocking is alright but some crates such as surf are designed with async in the first place, so the only method for it is block_on, so is there a simpler way to get a sync API?

oops sorry, i misunderstood your question. i'm niklaus friend's who currently learning how to sync/asynchronize multi-threaded stuff i don't have concrete answer on that, i just agree that the future is shiny.