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

Switch library to async #1

Merged
merged 9 commits into from
Jun 11, 2023
Merged

Switch library to async #1

merged 9 commits into from
Jun 11, 2023

Conversation

SplittyDev
Copy link
Member

@SplittyDev SplittyDev commented Jun 10, 2023

This PR switches the whole library over to async.

It introduces three new features:

  • blocking for stdlib I/O
  • tokio1 for full tokio support
  • async-std1 for full async-std support

The blocking feature is essentially a bring your own runtime feature, where standard Rust stdlib I/O functions are used. The behavior will essentially be the same as in the old non-async version of the library, but it still needs an async runtime to run. However, that way it can be used with non-supported async runtimes such as smol, and theoretically it should also work with the futures executor since it doesn't need a reactor.

Architectural Concerns

Right now, we're not enabling any feature by default, so when just adding it without any explicitly enabled features, the crate won't compile. I'm not sure that's the best solution, but defaulting to any runtime would require also passing default-features = false in addition to the actual feature, so that doesn't sound great either.

Update: I think I've found a great way to deal with this. The default feature now enables an implicit-blocking feature, which acts exactly like the explicit blocking feature, except when either tokio1 or async-std1 is present, in which case it acts like it doesn't exist.

The code for this is a bit funky, since we have to deal with constructs such as the following:

#[cfg(any(
  feature = "blocking",
  all(
    feature = "implicit-blocking",
    not(any(feature = "tokio1", feature = "async-std1")),
  )
))] {
  // Business as usual
}

But that shouldn't really matter. It's not too hard to maintain, and it unlocks a great way of dealing with this.
So, everything is blocking by default now, unless an explicit runtime feature is enabled.

@Neotamandua Neotamandua self-requested a review June 11, 2023 11:15
Copy link
Member

@Neotamandua Neotamandua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change feature naming to:
rt_tokio_1
rt_async-std_1

@SplittyDev SplittyDev merged commit 5f823a5 into main Jun 11, 2023
@SplittyDev SplittyDev deleted the feat/tokio_rt_1 branch June 11, 2023 12:53
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

Successfully merging this pull request may close these issues.

2 participants