3 ms·
Fibers "allow blocking and non-blocking implementations to share the same API" That's an interesting contrast to Python where the need to use "value = await fn
by simonw 5y ago
Fibers "allow blocking and non-blocking implementations to share the same API"
That's an interesting contrast to Python where the need to use "value = await fn()" v.s. "value = fn()" depending on whether or not that function is awaitable causes all kinds of API design complexity, all the way up to the existence of tools like https://github.com/python-trio/unasync https://github.com/python-trio/unasync which can code-generate the non-async version of a library from the async version.
- Ralfp 5y agoBut 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.
- jeltz 5y agoRuby has the same design where async is implemented on top of fibers.
- rbanffy 5y ago> allow blocking and non-blocking implementations to share the same API Sounds like an excellent way to create weird concurrency heisenbugs.