[Update: Compiler but in Xcode 13 beta 1 confirmed. See below update]
[Update2: New post up with some rough and ready benchmarking of AsyncSequence file reading using URLSession]
So what I wanted to know was how to efficiently and asynchronously read a file into a Data object using the new structured concurrency approach in Swift. The short version is that I didn't manage to get the async approaches to file reading working, not sure yet if I was doing it wrong or there are currently problems with the frameworks (I have filed a bug report with Apple - FB9177012). Either way the async approaches were crashing for me. And I do welcome responses letting me know what I'm doing wrong.
I couldn't see any exact APIs that looked right for asynchronously reading a file. The Meet AsyncSequence talk from WWDC gave one possibility although it didn't look very efficient of handling the URL as an AsyncSequence of bytes but I thought I would do some investigation to check. I later as you can see at the end of this post realised that URLSession provides the method I need for a one shot request (that also wasn't working). I still would like to test how the performance of all these approaches varies.
Update
Confirmation that it is a beta 1 from someone who worked on some of the AsyncSequence stuff at Apple.
Yeah there’s a compiler bug in b1, you can use the URLSession version for now. Sorry about that
— David Smith (@Catfish_Man) June 16, 2021
(Specifically, public actors don’t get along well with library evolution mode)
— David Smith (@Catfish_Man) June 16, 2021
End update