rewrite config & context, support tokio::main & tokio::test #2937
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 a bigger refactor and I have to apologize in advance for the size of it. I have ~8 WIP branches where I tried to do only parts of the rewrite, but all failed and now I ended up doing many things at once.
The initial motivation of this is coming from wanting to make progress on the sync/async migration in our codebase. Plenty of things were and still are not in the state I want them to be.
For some parts I took inspiration from the crates.io codebase and how they do it, which I like.
To wrap it up, this PR:
Config
struct to include a builder.Context
trait to astruct
that just includes everything. This made much of the migration much easier, less lifetime errors.tokio::runtime::Runtime
directly, now work with atokio::runtime::Handle
. This enables us to usetokio::test
and also later migrate ourmain
function totokio::main
.TestEnvironment
in your test, and the cleanup happens in theDrop
impl.some detail notes about the implementation:
bon
because I like its design more, and crates.io uses it too, but since I wanted to "stack" the builder calls it was too annoying to work with.wrapper
usage with the "new way".override_config
for now, some some selected ones. The rest follows later.known limitations for now:
tokio::test
doesn't work, it only works withflavor = multi_thread
. This is because I want to useblock_in_place
to be able to teardown the test env inDrop
. I took this from crates.io.after this PR I imagine:
async_wrapper