How to make file reads respect cooperative cancellation?

here is a very simplified illustration of a bug i am trying to fix today:

func f() async throws
{
    async
    let _:Void = self.readSomeFile()
    
    throw CancellationError.init()
}

the call to self.readSomeFile() can block indefinitely, because FileDescriptor.open(_:_:options:permissions:retryOnInterrupt:) blocks waiting for the file to become readable. (the file is not initially readable.)

because existing from an async scope implicitly cancels and waits for all async let tasks to finish, this causes f itself to hang forever, despite having aborted execution.

how do i make a file read respect cooperative cancellation?

the file is not initially readable

Readable in what sense? Because of file locking?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple