As I understand,
async functions return any type which implement the
Future trait, which is nothing but an abstraction over deferred computations (and large state machines). Now, let us assume that we have a multithreaded server, say the one in The Book for demonstration purposes, then what'd be the approach to make it asynchronous?
What I initially thought was this:
- A request is received
TcpStreamis sent to a worker thread which asynchronously reads the request
- The worker thread spawns a blocking task to process the request. Note: This step does disk I/O
- The worker thread writes to the stream, asynchronously
But I still can't outline an implementation. Can anyone point me in the right direction?