Hello! I recently made crate named async-executor that makes it quite easy to create custom executors with almost arbitrary task scheduling strategies. Sharing this here because I thought you mind find it useful. In fact, I noticed tikv/yatp a long time ago and had it specifically in mind when researching how to make executors simpler and more flexible :)
The first method spawns a new task, and the second method runs a single scheduled task. This API is pretty flexible because it allows you to compose multiple executors in interesting ways.
As a proof of concept, I made an executor with three task priorities (high, medium, low). Implementation:
It's not a lot of code at all! And it's fairly straightforward to extend this executor with new capabilities. For example, we could run lower priority tasks every 100 ms or so in order to ensure they don't get starved forever.
Hello! I recently made crate named
async-executor
that makes it quite easy to create custom executors with almost arbitrary task scheduling strategies. Sharing this here because I thought you mind find it useful. In fact, I noticed tikv/yatp a long time ago and had it specifically in mind when researching how to make executors simpler and more flexible :)https://docs.rs/async-executor/0.2.1/async_executor/
The interface is very simple. The
Executor
type essentially has the following methods:fn spawn<T: 'static>(&self, f: impl Future<Output = T> + 'static) -> Task<T>
async fn tick(&self)
The first method spawns a new task, and the second method runs a single scheduled task. This API is pretty flexible because it allows you to compose multiple executors in interesting ways.
As a proof of concept, I made an executor with three task priorities (high, medium, low). Implementation:
https://github.com/stjepang/async-executor/blob/master/examples/priority.rs
It's not a lot of code at all! And it's fairly straightforward to extend this executor with new capabilities. For example, we could run lower priority tasks every 100 ms or so in order to ensure they don't get starved forever.