Skip to content

Commit

Permalink
SocketPool + IdentifiableContinuation
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Apr 14, 2024
1 parent 374f722 commit 71c85f9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions FlyingSocks/Sources/SocketPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,23 @@ public final actor SocketPool<Queue: EventQueue>: AsyncSocketPool {

private func cancellAll() {
logger.logInfo("SocketPoll cancellAll")
try? queue.close()
state = .complete
waiting.cancellAll()
waiting = Waiting()
loop?.resume(throwing: CancellationError())
loop = nil
if let loop {
self.loop = nil
loop.resume(throwing: CancellationError())

Check warning on line 152 in FlyingSocks/Sources/SocketPool.swift

View check run for this annotation

Codecov / codecov/patch

FlyingSocks/Sources/SocketPool.swift#L151-L152

Added lines #L151 - L152 were not covered by tests
}
try? queue.close()
}

typealias Continuation = IdentifiableContinuation<Void, any Swift.Error>
private var loop: Continuation?
private var waiting = Waiting() {
didSet {
if !waiting.isEmpty, let continuation = loop {
continuation.resume()
loop = nil
if let loop, !waiting.isEmpty {
self.loop = nil
loop.resume()
}
}
}
Expand All @@ -172,9 +174,9 @@ public final actor SocketPool<Queue: EventQueue>: AsyncSocketPool {
}

private func cancelLoopContinuation(with id: Continuation.ID) {
if loop?.id == id {
loop?.resume(throwing: CancellationError())
loop = nil
if let loop, loop.id == id {
self.loop = nil
loop.resume(throwing: CancellationError())
}
}

Expand Down

0 comments on commit 71c85f9

Please sign in to comment.