Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As far as I understand, it's like this:

* Futures is a crate that provides a common abstraction for delimited continuations (JavaScript Promises).

* Tokio-Core provides an event loop abstraction (can't remember for sure but I think it uses Mio under the hood to abstract out epoll/kqueue/IOCP). Additionally, it provides the "core language" of Tokio, which are Futures (basically a Result that returns asynchronously), Streams (an Iterator that yields values asynchronously), and Sinks (a place to send data asynchronously).

* Tokio-Proto is an abstraction over Tokio-Core for composing various protocols together. This is done by defining protocol "codecs", which are used to define Streams and Sinks that send some unit of data along the protocol, and a Proto object that ties the codecs together. Then, to write servers with that protocol, you implement the Service trait, which can work at the higher-level protocol units (requests, responses, etc). If you're curious how this looks in an HTTP server for example, check out this (shameless plug) reverse proxy I wrote with Tokio: https://github.com/moosingin3space/hyproxy

* You would use Tokio for any asynchronous I/O task. You would use Futures whenever you want some sort of delimited continuation.

* You can use Futures without Tokio.

* The examples are mostly in the documentation here: https://tokio.rs/docs/getting-started/tokio/

If I'm wrong about any of this, please, someone, let me know!



> * Futures is a crate that provides a common abstraction for delimited continuations

I'm familiar with Java Futures, but can't tell if it's the same concept as what you're talking about. What exactly is a "delimited continuation"?


The best analogy I can give is to JavaScript promises, where you can do something once the future is resolved. In Java, this would be like the CompletableFuture class's thenApply function -- where you can write code that picks up once the future has been resolved.

A "delimited continuation" is that basic idea of having your code pick up once a future finishes executing.


They are roughly comparable, yes. Here's the explanation of futures specifically https://tokio.rs/docs/getting-started/futures/


Something like a -> (b -> r) -> r/the Cont monad?

E: I meant to reply to a a sibling.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: