Implementing our own async task queue
For this section, you will need to start a new workspace, as we will be building our own async queue and not relying on tokio. To get an appreciation for what is happening when we see async code in our web server, we are going to implement our own queue that schedules async tasks. Before we write any code, we need the following dependencies:
[dependencies]
async-task = "4.7.0"
futures-lite = "2.2.0"
flume = "0.11.0"
When we go through the steps to implement our own async task queue, we will demonstrate how and when we will use such dependencies. Before we get the chance, however, we also need to use the following structs and traits:
use std::{future::Future, panic::catch_unwind, thread};
use std::time::{Duration, Instant};
use std::pin::Pin;
use std::task::{Context, Poll};
use async_task::{Runnable, Task};
use futures_lite::future;
use std::sync::LazyLock;
We are now ready to move on to our first...