Conditionally async Peripheral traits #185
Labels
✨ feature
New things!
P-low
Low priority
T-peripheral traits
Topic: Peripheral Traits
T-wasm
Topic: WASM support
what
In the same vein as #184, when running in the browser, we want to be able to use web APIs that happen to be async to implement some of our peripheral traits. This is not something we can do today because the peripheral traits (and everything above them like the interpreter, the simulator, and
Control
) are not async.We should use the approach described in #184 to make these traits async when compiling for the web (wasm).
#[async_trait]
(and by extension theasync_on_wasm
macro described in #184) compose well with thedelegate
proc macros from [ambassador
] that are proposed as a replacement forperipheral_trait! { ... }
in #179; i.e. this:works fine. This way this works (on wasm) is that the
async_trait
macro expands first, rewriting the trait into something that looks like this:The
delegate
macro then uses the above as the trait definition and as the template for its delegated implementation. It then produces implementations that look like this:On non-wasm platforms, the
async_on_wasm
attribute just strips out all of theasync
s andawait
s from the trait definition and then lets thedelegate
macro operate as normal.Note that reversing the order of the attributes on _ does not work though, as you'd expect.
steps
peripheral_trait!
macro #179async_on_wasm
to the peripheral traitsbaseline-sim
withasync_on_wasm
and async/await as necessarywhere
branch:
feat/async-everywhere
open questions
The text was updated successfully, but these errors were encountered: