3 ms·
This works a lot better in JavaScript, which is exactly this model - a single threaded executor with async await. The problem you talk about is solved with func
by josephg 8mo ago
This works a lot better in JavaScript, which is exactly this model - a single threaded executor with async await. The problem you talk about is solved with function colouring. Async functions are marked as such. In general, sync functions can’t call async functions. (Well, you can invoke them. You just can’t run them to completion before returning).
For all the complaints about function colouring, I’m glad JavaScript has them. A sync function becoming an async function is a breaking API change. This is much better than the situation in Python, where yield points are invisible.
- pocksuppet 8mo agoUntil every function is async.
- nine_k 8mo agoIf a function is not pure, it very likely has to be async.
- pocksuppet 8mo agoWhich just brings you back to preemptive multithreading, but without being able to use all the cores you paid for.
- bombolo 8mo ago[dead]
- josephg 8mo agoExcept nobody writes code like that. It would be horrible. Sync functions perform better than async functions, and they give more guarantees to the caller. They're strictly better, when you can use them. If you find yourself making everything async, your design is bad and you should refactoring your code.