Implementing our own async task queue
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 by carrying out the following steps:
Creating an async task queue that schedules async tasks so the main branch can spawn such tasks.
Building our own async sleep functionality.
Test running our async queue in the main thread.
Before we implement any of these steps, we need the following dependencies:
[dependencies]
async-task = "4.7.0"
futures-lite = "2.2.0"
once_cell = "1.19.0"
flume = "0.11.0"
When we go through the steps, 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...