I understand this video a little differently. It isn’t async
and await
that are difficult painful so much as trying to use them while also using non-async
code.
I watched the video over 3 days, but a project I work on does something like this and it doesn’t seem quite as painful as they make it out to be. IIRC (I’m on another project at the moment) the synchronous api basically wrap calls to the asynchronous api by spawning a blocking tokio thread and using async
in there. It’s relatively easy and there’s no code duplication.
Caveats:
- We do feature-flag it, so that cargo builds separate products for synchronous and asynchronous usage.
- I’ve implemented some of the API (on both the synchronous and asynchronous ends), but I didn’t design the feature flagging. What looks relatively easy to me may have been a bear to design.
- I also don’t like how
async
taints everything it touches. That’s one reason I asked about this in Ada a while back. - I think there was another caveat, but I’ve forgotten it.