@@ -69,28 +69,30 @@ import SystemPackage
69
69
// Read while triggering an I/O error
70
70
do {
71
71
let fd = try Path . root. str. withPlatformString { try FileDescriptor . open ( $0, . readOnly) }
72
- let fh = FileHandle ( fileDescriptor: fd. rawValue, closeOnDealloc: false )
72
+ try await fd. closeAfter {
73
+ let fh = FileHandle ( fileDescriptor: fd. rawValue, closeOnDealloc: false )
73
74
74
- if #available( macOS 15 , iOS 18 , tvOS 18 , watchOS 11 , visionOS 2 , * ) {
75
- var it = fh. bytes ( ) . makeAsyncIterator ( )
76
- try fd. close ( )
75
+ if #available( macOS 15 , iOS 18 , tvOS 18 , watchOS 11 , visionOS 2 , * ) {
76
+ var it = fh. bytes ( ) . makeAsyncIterator ( )
77
77
78
- await #expect( throws: ( any Error ) . self) {
79
- while let _ = try await it. next ( ) {
78
+ // Can't read a directory
79
+ await #expect( throws: ( any Error ) . self) {
80
+ while let _ = try await it. next ( ) {
81
+ }
80
82
}
81
- }
82
- } else {
83
- var it = fh. _bytes ( ) . makeAsyncIterator ( )
84
- try fd. close ( )
83
+ } else {
84
+ var it = fh. _bytes ( ) . makeAsyncIterator ( )
85
85
86
- await #expect( throws: ( any Error ) . self) {
87
- while let _ = try await it. next ( ) {
86
+ // Can't read a directory
87
+ await #expect( throws: ( any Error ) . self) {
88
+ while let _ = try await it. next ( ) {
89
+ }
88
90
}
89
91
}
90
92
}
91
93
}
92
94
93
- // Read part of a file, then close the handle
95
+ // Read part of a file, then cancel the task
94
96
do {
95
97
let condition = CancellableWaitCondition ( )
96
98
0 commit comments