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

confusion specific to Java #141

Open nikomatsakis opened 3 years ago

nikomatsakis commented 3 years ago

Brief summary

Alan is accustomed to implementing services in Java He has design patterns in his mind that don't work in Rust. He also gets confused by specific things around async Rust / Rust futures. What are they?

Optional details

nikomatsakis commented 3 years ago

Example I've heard: In Java, a Future represents a value executing in another thread. Futures in Rust do not necessarily represent that.

urhein commented 3 years ago

Not sure how much this helps, but this is already a misconception in Java: Futures don't necessarily execute on a different thread (although that may be the most common case), and they may not even strictly have an execution attached to them (e.g. the CompletableFuture).

Just conceptually, Java's ("A Future represents the result of an asynchronous computation") and Rust's ("A future represents an asynchronous computation") definitions are pretty similar. What confused me the most were the differences in behavior:

nikomatsakis commented 3 years ago

@urhein I was talking to some folks and we realized that Rust's Future is really more analogous to Java's Callable.