3 ms·
Nice hack :) I don't see myself using this in any kind of real code at this stage, although it might serve as a base for a more comprehensive library of Rust-s
by Yoric 7y ago
Nice hack :)
I don't see myself using this in any kind of real code at this stage, although it might serve as a base for a more comprehensive library of Rust-style futures.
- naasking 7y agoMy intent was to play around with different approaches for Arduino programming. I saw a bunch of blocking functions, like delay(), and thought that seemed silly and made me wish for async/await. I realised at that point that I could do it via macros with the same approach used by protothreads.
- bxparks 7y agoI found that computed-goto (https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html) is cleaner than Duff's Device for this sort of thing. (It works for clang compiler too.) Take a look at https://github.com/bxparks/AceRoutine https://github.com/bxparks/AceRoutine for an Arduino library that uses computed-goto.
- naasking 7y agoAgreed, definitely more efficient and probably flexible, but two minor downsides: 1. not portable C 2. requires more storage for each continuation (4 bytes vs. 2)