Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple way to create custom executors #41

Open
ghost opened this issue Aug 29, 2020 · 1 comment
Open

A simple way to create custom executors #41

ghost opened this issue Aug 29, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 29, 2020

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.

@BusyJay
Copy link
Member

BusyJay commented Aug 31, 2020

Thanks for recommendation! It's a fantastic library! In yatp, tasks don't have fixed priority, which doesn't seem to fit in the model though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant