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

Make smol truly live up to its name #188

Merged
12 commits merged into from
Jul 15, 2020
Merged

Make smol truly live up to its name #188

12 commits merged into from
Jul 15, 2020

Conversation

ghost
Copy link

@ghost ghost commented Jul 14, 2020

This is the final step in smol's evolution. The crate has been broken into:

  • blocking, replacing smol::reader(), smol::writer(), smol::iter(), and smol::block_on().
  • async-io, replacing smol::Async and smol::Timer.
  • multitask, replacing smol::run().

The adapters for blocking functions have always been independent of the actual runtime, so it was natural to break those parts into blocking.

Previously, Async and Timer wouldn't work if you didn't call run(). While it was nice not to have background threads driving the runtime, this design turned out to be more pain that is worth. Now, async-io will spawn a fallback background thread driving the reactor, but executors can still drive the reactor using async_io::parking. This way we can drive the reactor and the executor on the same thread, thus getting amazing performance while still keeping things simple.

The executor in multitask is now just a state machine that users can drive on their own however they wish. All you need to do is to keep calling .tick() to run a single task at a time. This gets us much more flexibility than before. Now you can easily run two or more executors on the same thread simply by doing ex1.tick(); ex2.tick(); ex3.tick();. This opens up a world of possibilities - e.g. you can implement task priorities by creating an executor per priority level, and then "ticking" all executors on the same thread.

Smol is now just a tiny wrapper around multitask, and it works really well in small async programs and unit tests. For anything more demanding, you can trivially write your own custom smol.

@ghost ghost mentioned this pull request Jul 14, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

0 participants