3 ms·
It's very heavy to do this is it not? Like you inspect the function on each call to figure out if it's async or not?
by mattbillenstein 6y ago
It's very heavy to do this is it not? Like you inspect the function on each call to figure out if it's async or not?
- PaulHoule 6y agoFor things that happen at UI speed it isn't bad. If I wanted to do something a million times a second I'd worry about it. Some Javascript frameworks, such as Vue, often do something similar in that you can pass either a sync or async callback and it does the right thing for either. In that case you could potentially inspect the function once and call it many times.
- 1337shadow 6y agoYou don't inspect the function, but the result. Is it a coroutine ? If so, it needs to be awaited (see my example above). I believe this also would allow non-async function to return a coroutine I suppose. Anyway, in this case chances are that there will be no performance overhead if there's any io bound operation running in the coroutine so it should run the iscoroutine check of the result and the await call before the function is done.