Discussion
Loading...

Post

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Jan :rust: :ferris:
@janriemer@floss.social  ·  activity timestamp 3 weeks ago

Async #Rust is actually awesome! awesome

The last few days I've built a prototype(!) of a global "Hotkey" system e.g.:

Press & Hold LCtrl + Space
=> an async stream starts and only finishes if:
- another key is pressed or
- one of the Hotkeys is released

If it is not clear by now: this is a state-machine, which fits perfectly into Rust's #async model!

And the best part: This is actually the first time I've ever touched async #RustLang! Such a pleasant experience!

1/?

#AsyncRust

  • Copy link
  • Flag this post
  • Block
Jan :rust: :ferris:
@janriemer@floss.social replied  ·  activity timestamp 3 weeks ago

For this to work, I had to transform a sync callback with the keypress events (from device_query crate) to an async stream.
This can be done with a channel:
- use send (blocking-variant) from within the callback
- use async receiver in your stream impl

In the following post, I'll list some crates that have helped me achieve this...

2/?

  • Copy link
  • Flag this comment
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0-rc.2.21 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login