[Semi-OT] Fibers vs. Async / Await
René Zwanenburg
renezwanenburg at gmail.com
Thu May 12 11:47:48 UTC 2022
On Thursday, 12 May 2022 at 06:04:06 UTC, bauss wrote:
> You don't have to have a "Task" type that you declare, it could
> simply be T and then the function is just marked async and T
> automatically becomes Task!T.
That would help a little. Doesn't get rid of the await though.
> It's easy to fix, don't allow implicit conversions between
> Task!T and T and thus whenever you attempt to use the result
> you're forced to await it because otherwise you'd get an error
> from the compiler due to mismatching types.
Right. .Net doesn't do implicit conversion either, I was thinking
of functions that are void / just Task, like writing to a
database. Assuming you use exceptions to report problems.
> It doesn't really put anymore pressure on the GC. The compiler
> converts your code to a state machine and that hardly adds any
> overhead. It makes your functions somewhat linear, that's it.
> It doesn't require many more allocations, at least not more
> than fibers.
Are you sure about this? The state machine needs to be stored
somewhere. I'd think we would need something similar to a
delegate: a fixed-size structure that can be passed around, with
a pointer to a variable sized context / state machine living on
the heap.
More information about the Digitalmars-d
mailing list