I wonder if the error prompting this discussion stems from this prior discussion:
Pitch: Unavailability from asynchronous contexts
Just to verify, my mental model was that a span of code between suspension points always runs on the same Thread. I concluded that Thread
derivatives (.current
and local's) would be consistent and correct within that span, but not across suspension points.
But your workaround requiring a refactoring of code suggests that Thread
derivatives could be invalid in an async context even within a code span. I can imagine async runtime's where that's true, so perhaps that's the safest assumption (even if it's viable now on some implementations). That would would make it important to identify (implicitly) Thread-dependent API's to avoid in async code.