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

Minimal async support #2

Merged
merged 4 commits into from Nov 20, 2023
Merged

Minimal async support #2

merged 4 commits into from Nov 20, 2023

Conversation

rklaehn
Copy link
Collaborator

@rklaehn rklaehn commented Nov 20, 2023

Use flume channels instead of std::mpsc channel to have the option to do async.

Expose a minimal async API under a feature flag, so you can avoid needless spawn_blocking to e.g. wait for a result.

We are using flume channels both for single responses and stream responses.
The alternative would be to use a futures oneshot receiver, but that does
not have a blocking option.

What is great about flume is that it has a completely workable blocking and
non-blocking API.
The async part is not as convenient as the sync support. E.g. all async
fns have an _async suffix, and Response does not implement Stream. But
you can use it without unneccessary spawn_blocking, and that's the main
thing.
This is to minimize dependencies for the non async version:

❯ cargo tree --no-default-features | grep -C 10 flume
mainline v0.2.0 (/Users/rklaehn/projects_git/mainline-rs)
├── crc v3.0.1
│   └── crc-catalog v2.4.0
├── flume v0.11.0
│   ├── nanorand v0.7.0
│   │   └── getrandom v0.2.11
│   │       ├── cfg-if v1.0.0
│   │       └── libc v0.2.150
│   └── spin v0.9.8
│       └── lock_api v0.4.11
│           └── scopeguard v1.2.0
│           [build-dependencies]
│           └── autocfg v1.1.0
├── rand v0.8.5

❯ cargo tree | grep -C 10 flume
mainline v0.2.0 (/Users/rklaehn/projects_git/mainline-rs)
├── crc v3.0.1
│   └── crc-catalog v2.4.0
├── flume v0.11.0
│   ├── futures-core v0.3.29
│   ├── futures-sink v0.3.29
│   ├── nanorand v0.7.0
│   │   └── getrandom v0.2.11
│   │       ├── cfg-if v1.0.0
│   │       └── libc v0.2.150
│   └── spin v0.9.8
│       └── lock_api v0.4.11
│           └── scopeguard v1.2.0
│           [build-dependencies]
also behind the feature gate. Not using tokio::test to avoid the dependency
@rklaehn rklaehn marked this pull request as ready for review November 20, 2023 10:16
@Nuhvi Nuhvi merged commit 7f5adc6 into main Nov 20, 2023
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.

None yet

2 participants