3 ms·
Would it be possible to make functions generic over coroutines/async? One of the worst parts of async is there's an infectious duplication of pretty much all l
by infogulch 9y ago
Would it be possible to make functions generic over coroutines/async?
One of the worst parts of async is there's an infectious duplication of pretty much all library code where there are separate sync/async versions of everything. See C# DoXxx() & DoXxxAsync() everywhere, where the only difference between the two implementations are an annotation and some keywords sprinkled throughout. If rust can do the same thing without doubling the code/api surface/documentation across all libraries that would allay the fears of many opponents.
- xfer 9y agoYou can do DoXxx() using DoXxxAsync() by calling wait() on the future it returns. No duplicated code necessary.
- infogulch 9y agoIt's nice that that'll work but it's... kinda gross. Can it call wait() automatically via some auto type conversion? Ideally in a synchronous context it would call wait(), and in an async context it would automatically annotate await (and you could always override by calling wait() manually).
- skyde 9y agoHaskell is doing this already with par and seq function to control parallel and lazy evaluation. I believe we should have something like this for Async