Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions FlyingFox/Sources/HTTPRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,9 @@ public struct HTTPRoute: Sendable {
}
}

@available(*, deprecated, renamed: "methods", message: "Use ``methods`` instead")
@available(*, unavailable, renamed: "methods", message: "Use ``methods`` instead")
public var method: Component {
if methods == HTTPMethod.allMethods {
return .wildcard
} else {
let firstMethod = HTTPMethod.sortedMethods
.filter { methods.contains($0) }
.first!
.rawValue
return .caseInsensitive(firstMethod)
}
fatalError("Use methods instead")
}
}

Expand Down
2 changes: 1 addition & 1 deletion FlyingFox/Tests/HTTPResponse+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension HTTPResponse {

static func make(headers: [HTTPHeader: String] = [:],
webSocket handler: some WSHandler) -> Self {
HTTPResponse(headers: headers,
HTTPResponse(headers: HTTPHeaders(headers),
webSocket: handler)
}

Expand Down
8 changes: 0 additions & 8 deletions FlyingFox/Tests/HTTPRouteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,6 @@ struct HTTPRouteTests {
}
#endif

@Test
func deprecated_Method() {
#expect(HTTPRoute("/fish/*").method == .wildcard)
#expect(HTTPRoute("GET /fish/*").method == .caseInsensitive("GET"))
#expect(HTTPRoute("PUT /fish/*").method == .caseInsensitive("PUT"))
#expect(HTTPRoute("GET,PUT /fish/*").method == .caseInsensitive("GET"))
}

@Test
func routeParameters() {
let route = HTTPRoute("GET /mock/:id")
Expand Down
4 changes: 2 additions & 2 deletions FlyingFox/Tests/HTTPServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ actor HTTPServerTests {

func startServerWithPort(_ server: HTTPServer, preferConnectionsDiscarding: Bool = true) async throws -> UInt16 {
self.stopServer = server
Task {
_ = Task {
try await HTTPServer.$preferConnectionsDiscarding.withValue(preferConnectionsDiscarding) {
try await server.run()
}
Expand Down Expand Up @@ -663,7 +663,7 @@ actor HTTPServerTests {
return true
}

Task { try await server.run() }
_ = Task { try await server.run() }
self.stopServer = server

#expect(try await waiting.value == true)
Expand Down
17 changes: 16 additions & 1 deletion FlyingSocks/Sources/AsyncBufferedSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public protocol AsyncBufferedSequence<Element>: AsyncSequence, Sendable where As

}

// Iterators are taken out of an actor and advanced with the nonisolated `nextBuffer`,
// so their conformance must not be isolated to a global actor (SendableMetatype).
#if compiler(>=6.2)
public protocol AsyncBufferedIteratorProtocol<Element>: AsyncIteratorProtocol, SendableMetatype {
// Buffered elements are returned in this collection type
associatedtype Buffer: Collection where Buffer.Element == Element

/// Retrieves available elements from the buffer. Suspends if 0 elements are available.
/// - Parameter count: The suggested number of elements to return
/// - Returns: Collection with between 1 and the number elements that was requested. Nil is returned if the sequence has ended.
mutating func nextBuffer(suggested count: Int) async throws -> Buffer?
}
#else
public protocol AsyncBufferedIteratorProtocol<Element>: AsyncIteratorProtocol {
// Buffered elements are returned in this collection type
associatedtype Buffer: Collection where Buffer.Element == Element
Expand All @@ -43,6 +56,7 @@ public protocol AsyncBufferedIteratorProtocol<Element>: AsyncIteratorProtocol {
/// - Returns: Collection with between 1 and the number elements that was requested. Nil is returned if the sequence has ended.
mutating func nextBuffer(suggested count: Int) async throws -> Buffer?
}
#endif

extension AsyncBufferedIteratorProtocol where Element: Sendable {

Expand All @@ -51,7 +65,8 @@ extension AsyncBufferedIteratorProtocol where Element: Sendable {
/// non-Sendable `Buffer` crossing into an actor, and it can't be wrapped in
/// `Disconnected` because it shares the iterator's region.
mutating func nextElements(suggested count: Int) async throws -> [Element]? {
try await nextBuffer(suggested: count).map(Array.init)
guard let buffer = try await nextBuffer(suggested: count) else { return nil }
return Array(buffer)
}
}

Expand Down
2 changes: 1 addition & 1 deletion FlyingSocks/Sources/AsyncSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ private actor ClientPoolLoader {
}
try await pool.prepare()
isStarted = true
Task { try await pool.run() }
_ = Task { try await pool.run() }
return pool
}
}
Expand Down
22 changes: 18 additions & 4 deletions FlyingSocks/Sources/IdentifiableContinuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ package func withIdentifiableContinuation<T>(
let state = Mutex((isStarted: false, isCancelled: false))
nonisolated(unsafe) let body = body
return await withTaskCancellationHandler {
await withCheckedContinuation(isolation: isolation, function: function) {
let continuation = IdentifiableContinuation(id: id, continuation: $0)
let operation = { (checked: CheckedContinuation<T, Never>) in
let continuation = IdentifiableContinuation(id: id, continuation: checked)
body(continuation)
let sendCancel = state.withLock {
$0.isStarted = true
Expand All @@ -69,6 +69,13 @@ package func withIdentifiableContinuation<T>(
handler(id)
}
}
// Swift 6.4 deprecates the `isolation:` overload for a nonisolated(nonsending) one,
// which inherits the isolation. Older compilers need it passed explicitly.
#if compiler(>=6.4)
return await withCheckedContinuation(function: function, operation)
#else
return await withCheckedContinuation(isolation: isolation, function: function, operation)
#endif
} onCancel: {
let sendCancel = state.withLock {
$0.isCancelled = true
Expand Down Expand Up @@ -105,8 +112,8 @@ package func withIdentifiableThrowingContinuation<T>(
let state = Mutex((isStarted: false, isCancelled: false))
nonisolated(unsafe) let body = body
return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation(isolation: isolation, function: function) {
let continuation = IdentifiableContinuation(id: id, continuation: $0)
let operation = { (checked: CheckedContinuation<T, any Error>) in
let continuation = IdentifiableContinuation(id: id, continuation: checked)
body(continuation)
let sendCancel = state.withLock {
$0.isStarted = true
Expand All @@ -116,6 +123,13 @@ package func withIdentifiableThrowingContinuation<T>(
handler(id)
}
}
// Swift 6.4 deprecates the `isolation:` overload for a nonisolated(nonsending) one,
// which inherits the isolation. Older compilers need it passed explicitly.
#if compiler(>=6.4)
return try await withCheckedThrowingContinuation(function: function, operation)
#else
return try await withCheckedThrowingContinuation(isolation: isolation, function: function, operation)
#endif
} onCancel: {
let sendCancel = state.withLock {
$0.isCancelled = true
Expand Down
2 changes: 1 addition & 1 deletion FlyingSocks/Tests/AsyncSocketTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct AsyncSocketTests {
let (s1, s2) = try await AsyncSocket.makePair()

async let d2 = s2.readString(length: 12)
Task {
_ = Task {
try await s1.writeString("Fish & Chips")
}

Expand Down
Loading