4 ms·
Doing that in Rust can be a footgun if the synchronous code blocks for too long. You often want a separate threadpool for calling those functions. It works grea
by conradev 2y ago
Doing that in Rust can be a footgun if the synchronous code blocks for too long. You often want a separate threadpool for calling those functions. It works great in Swift, though!
Swift mitigates a lot of the function coloring pain: synchronous methods can conform to asynchronous protocol requirements, thanks to the compiler generating thunks (at least, I think that’s how it works)
- adastra22 2y agoA thunk wouldn't be zero-cost.
- skavi 2y agoOf course. But the common case of calling a synchronous function from a Future is something trivial like a + b.
- metaltyphoon 2y agoIsn’t this what spawn_blocking and block_in_place do?
- saagarjha 2y agoThe opposite, actually. Swift (Concurrency) doesn't really have a good way to do the kind of thing spawn_blocking does. (Though, some would argue that the very design of spawn_blocking is not good to begin with.)
- conradev 2y agoYes! In Swift there is no need to do this sort of differentiation, though, which is more ergonomic. Different trade-offs.