Make smol truly live up to its name #188
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the final step in smol's evolution. The crate has been broken into:
blocking
, replacingsmol::reader()
,smol::writer()
,smol::iter()
, andsmol::block_on()
.async-io
, replacingsmol::Async
andsmol::Timer
.multitask
, replacingsmol::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
andTimer
wouldn't work if you didn't callrun()
. 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 usingasync_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 doingex1.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.