You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func provide(_ result:Result<Element?,Error>, in continuation:CheckedContinuation<Void,Error>){
25
25
/// If reads were cancelled, propagate the cancellation to the provider without saving the result.
26
-
if wasCancelled {throwCancellationError()}
26
+
guard !wasCancelled else{
27
+
continuation.resume(throwing:CancellationError())
28
+
return
29
+
}
27
30
28
-
/// Enqueue the provided result and continue the task once it is ready to be consumed.
29
-
tryawaitwithCheckedThrowingContinuation{ continuation in
30
-
/// Ideally, no more than one pending event should be queued up, as a second event means backpressure isn't working.
31
-
precondition(pendingWriteEvents.isEmpty,"More than one event has been queued on the stream.")
32
-
33
-
/// If a read is currently pending, signal that a new result has been provided.
34
-
iflet pendingReadContinuation {
35
-
self.pendingReadContinuation =nil
36
-
pendingReadContinuation.resume(with: result)
37
-
continuation.resume()
38
-
}else{
39
-
/// If we aren't ready for events, queue the event and suspend the task until events are ready. This will stop more values from being provided (ie. the backpressure at work).
40
-
pendingWriteEvents.append((continuation, result))
41
-
}
31
+
/// Ideally, no more than one pending event should be queued up, as a second event means backpressure isn't working.
32
+
precondition(pendingWriteEvents.isEmpty,"More than one event has been queued on the stream.")
33
+
34
+
/// If a read is currently pending, signal that a new result has been provided.
35
+
iflet pendingReadContinuation {
36
+
self.pendingReadContinuation =nil
37
+
pendingReadContinuation.resume(with: result)
38
+
continuation.resume()
39
+
}else{
40
+
/// If we aren't ready for events, queue the event and suspend the task until events are ready. This will stop more values from being provided (ie. the backpressure at work).
0 commit comments