@@ -254,9 +254,9 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
254
254
255
255
final class _Context {
256
256
let storage : _Storage ?
257
- let produce : ( ) async throws -> Element ?
257
+ let produce : ( ) async throws ( Failure ) -> Element ?
258
258
259
- init ( storage: _Storage ? = nil , produce: @escaping ( ) async throws -> Element ? ) {
259
+ init ( storage: _Storage ? = nil , produce: @escaping ( ) async throws ( Failure ) -> Element ? ) {
260
260
self . storage = storage
261
261
self . produce = produce
262
262
}
@@ -415,6 +415,24 @@ extension AsyncThrowingStream: AsyncSequence {
415
415
public mutating func next( ) async throws -> Element ? {
416
416
return try await context. produce ( )
417
417
}
418
+
419
+ /// The next value from the asynchronous stream.
420
+ ///
421
+ /// When `nextElement()` returns `nil`, this signifies the end of the
422
+ /// `AsyncThrowingStream`.
423
+ ///
424
+ /// It is a programmer error to invoke `nextElement()` from a concurrent
425
+ /// context that contends with another such call, which results in a call to
426
+ /// `fatalError()`.
427
+ ///
428
+ /// If you cancel the task this iterator is running in while `nextElement()`
429
+ /// is awaiting a value, the `AsyncThrowingStream` terminates. In this case,
430
+ /// `nextElement()` may return `nil` immediately, or else return `nil` on
431
+ /// subsequent calls.
432
+ @available ( SwiftStdlib 5 . 11 , * )
433
+ public mutating func nextElement( ) async throws ( Failure) -> Element ? {
434
+ return try await context. produce ( )
435
+ }
418
436
}
419
437
420
438
/// Creates the asynchronous iterator that produces elements of this
0 commit comments