Skip to content

Conversation

swhitty
Copy link
Owner

@swhitty swhitty commented Aug 27, 2022

Adds CancellingContinuation which is a thing wrapper on CheckedContinuation that detects cancellation and throws CancellationError.

Actors can then use defer { } to ensure any cleanup occurs on the actor without escaping isolated methods:
https://bugs.swift.org/browse/SR-15745

actor Foo {

  private var waiting = Set<CancellingContinuation<Void, Never>>

  func bar() async throws {
     let continuation = CancellingContinuation<Void, Never>()
     waiting.insert(continuation)
     defer { waiting.remove(continuation) }
     return try await continuation.value
  }
}

@codecov
Copy link

codecov bot commented Aug 27, 2022

Codecov Report

Merging #37 (37f5be7) into main (d4647bf) will decrease coverage by 0.20%.
The diff coverage is 96.77%.

@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   99.62%   99.42%   -0.21%     
==========================================
  Files          43       43              
  Lines        2124     2081      -43     
==========================================
- Hits         2116     2069      -47     
- Misses          8       12       +4     
Impacted Files Coverage Δ
FlyingFox/Sources/URLSession+Async.swift 93.33% <93.75%> (-6.67%) ⬇️
FlyingSocks/Sources/CancellingContinuation.swift 96.00% <96.00%> (ø)
FlyingFox/Sources/HTTPServer+Listening.swift 100.00% <100.00%> (ø)
FlyingSocks/Sources/PollingSocketPool.swift 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@swhitty swhitty merged commit 6f12e83 into main Aug 27, 2022
@swhitty swhitty deleted the cancelling-continuation branch August 27, 2022 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant