5 ms·
But if you are writing framework or library that has to deal with both, its: result = fn() if isawaitable(result): result = await result And t
by Ralfp 5y ago
But if you are writing framework or library that has to deal with both, its:
result = fn()
if isawaitable(result):
result = await result
And turns out isawaitable is not that fast so things like GraphQL libraries that run above logic thousands of times per request get noticeably slow.
- simonw 5y agoI wrote a bit about that pattern last year: https://simonwillison.net/2020/Sep/2/await-me-maybe/ https://simonwillison.net/2020/Sep/2/await-me-maybe/ I didn't realize it had a significant performance overhead though, I should look into that.