Daily Thought - 2024-12-14
< back to listOf all the effects in Rust, asynchrony is the most interesting one. In a weird way, it's a step back from panics, as it uses the return value again, to transport the effect. As a result, any caller of an asynchronous function needs to handle the effect. If it can't (because it's not async itself), that's a pain. (That's called function coloring.)
But in every other way, it's more powerful, and much closer to what a full effect system could look like. Here, a function that triggers the effect can be resumed. And while every caller needs to handle the effect, strictly speaking, the language includes enough magic to make it easy to just pass it on.
In that way, handlers can be nested. A handler lower in the call chain could decide which of two async functions to resume next, for example. But if it doesn't want to resume either right now, it can itself trigger the "async" effect and let a handler higher up (and eventually the global executor) decide what happens next.
Having looked at those ad-hoc effects, we can now imagine a unified system that could cover all of them. That's a topic for tomorrow though!
Hey, you! Want to subscribe to my daily thoughts? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email whenever I post a new one.