Open nikomatsakis opened 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.
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:
await
ing or other methods). In Java, the class that hands you the Future
will (almost always) do this for you.Future::poll
as I'm using Future.get()
in Java. Future.get()
as many times as I want, and in as many threads as I want.@urhein I was talking to some folks and we realized that Rust's Future
is really more analogous to Java's Callable
.
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