tokio-rs / doc-push

Tokio doc blitz effort - A concerted effort to improve Tokio's documentation.
MIT License
50 stars 7 forks source link

Composing Futures from Different Libraries #16

Open rylev opened 6 years ago

rylev commented 6 years ago

Composing multiple libraries that use Futures but don't know about each other is probably a very common scenario. For instance, if I want to use hyper and the async API of redis-rs, how do I do that without spawning two runtimes?

carllerche commented 6 years ago

Do you think this would go in the Putting it Together section of "Futures, Streams, and Sinks"?

rylev commented 6 years ago

That could work. The only issue is that Futures and Streams will definitely be mentioned before that section (even in the hello-world guide). We'll need to figure out how to appropriately introduce them without confusing beginner readers or having to fully explain them so early.

carllerche commented 6 years ago

What do you mean by futures from different libraries? All futures should run on any runtime. You shouldn't need to?

Maybe this is a question to be addressed though. Why did you think you would need a runtime per library?

rylev commented 6 years ago

@carllerche I was watching @jonhoo's latest stream and one of the project's he committed to was using a Futures thread pool inside of a hyper application. This seemed to be because the author of the crate didn't really understand how to compose some asynchronous work he needed to do in his application code with the already running tokio runtime used by hyper. I feel like this is a possible point of confusion for people. Perhaps I can rename the issue to something that more clearly conveys this point?

carllerche commented 6 years ago

Is this related to https://github.com/bcmyers/argonautica/pull/7?

Perhaps this could go in the: "Tokio for libraries" section?

jonhoo commented 6 years ago

Ah, no, I think he's referring to https://github.com/graphql-rust/juniper/pull/256