Skip to content

Commit

Permalink
Revert "Add Sendable conformances to WebsocketKit (#131)" (#135)
Browse files Browse the repository at this point in the history
This reverts commit c2e0aa4.
  • Loading branch information
gwynne authored May 25, 2023
1 parent c2e0aa4 commit 0b43ce5
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 205 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ concurrency:
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [ main ] }

jobs:

vapor-integration:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
DerivedData
.swiftpm
Package.resolved
.devcontainer/
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio.git", from: "2.53.0"),
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.16.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.24.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.16.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.11.4"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
],
targets: [
.target(name: "WebSocketKit", dependencies: [
Expand Down
46 changes: 19 additions & 27 deletions Sources/WebSocketKit/Concurrency/WebSocket+Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,34 @@ extension WebSocket {
try await close(code: code).get()
}

public func onText(_ callback: @Sendable @escaping (WebSocket, String) async -> ()) {
self.eventLoop.execute {
self.onText { socket, text in
Task {
await callback(socket, text)
}
public func onText(_ callback: @escaping (WebSocket, String) async -> ()) {
onText { socket, text in
Task {
await callback(socket, text)
}
}
}

public func onBinary(_ callback: @Sendable @escaping (WebSocket, ByteBuffer) async -> ()) {
self.eventLoop.execute {
self.onBinary { socket, binary in
Task {
await callback(socket, binary)
}
public func onBinary(_ callback: @escaping (WebSocket, ByteBuffer) async -> ()) {
onBinary { socket, binary in
Task {
await callback(socket, binary)
}
}
}

public func onPong(_ callback: @Sendable @escaping (WebSocket) async -> ()) {
self.eventLoop.execute {
self.onPong { socket in
Task {
await callback(socket)
}
public func onPong(_ callback: @escaping (WebSocket) async -> ()) {
onPong { socket in
Task {
await callback(socket)
}
}
}

public func onPing(_ callback: @Sendable @escaping (WebSocket) async -> ()) {
self.eventLoop.execute {
self.onPing { socket in
Task {
await callback(socket)
}
public func onPing(_ callback: @escaping (WebSocket) async -> ()) {
onPing { socket in
Task {
await callback(socket)
}
}
}
Expand All @@ -85,7 +77,7 @@ extension WebSocket {
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
onUpgrade: @escaping (WebSocket) async -> ()
) async throws {
return try await self.connect(
to: url,
Expand All @@ -105,7 +97,7 @@ extension WebSocket {
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
onUpgrade: @escaping (WebSocket) async -> ()
) async throws {
return try await self.connect(
to: url,
Expand All @@ -129,7 +121,7 @@ extension WebSocket {
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) async -> ()
onUpgrade: @escaping (WebSocket) async -> ()
) async throws {
return try await self.connect(
scheme: scheme,
Expand Down
4 changes: 4 additions & 0 deletions Sources/WebSocketKit/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
@_documentation(visibility: internal) @_exported import protocol NIOCore.EventLoopGroup
@_documentation(visibility: internal) @_exported import struct NIOCore.EventLoopPromise
@_documentation(visibility: internal) @_exported import class NIOCore.EventLoopFuture

@_documentation(visibility: internal) @_exported import struct NIOHTTP1.HTTPHeaders

@_documentation(visibility: internal) @_exported import struct Foundation.URL

#else
Expand All @@ -17,7 +19,9 @@
@_exported import protocol NIOCore.EventLoopGroup
@_exported import struct NIOCore.EventLoopPromise
@_exported import class NIOCore.EventLoopFuture

@_exported import struct NIOHTTP1.HTTPHeaders

@_exported import struct Foundation.URL

#endif
10 changes: 5 additions & 5 deletions Sources/WebSocketKit/WebSocket+Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension WebSocket {
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
onUpgrade: @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
guard let url = URL(string: url) else {
return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL)
Expand Down Expand Up @@ -45,7 +45,7 @@ extension WebSocket {
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
onUpgrade: @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
let scheme = url.scheme ?? "ws"
return self.connect(
Expand Down Expand Up @@ -83,7 +83,7 @@ extension WebSocket {
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
onUpgrade: @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
return WebSocketClient(
eventLoopGroupProvider: .shared(eventLoopGroup),
Expand Down Expand Up @@ -129,7 +129,7 @@ extension WebSocket {
proxyConnectDeadline: NIODeadline = NIODeadline.distantFuture,
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
onUpgrade: @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
return WebSocketClient(
eventLoopGroupProvider: .shared(eventLoopGroup),
Expand Down Expand Up @@ -171,7 +171,7 @@ extension WebSocket {
proxyConnectDeadline: NIODeadline = NIODeadline.distantFuture,
configuration: WebSocketClient.Configuration = .init(),
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
onUpgrade: @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
guard let url = URL(string: url) else {
return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL)
Expand Down
Loading

0 comments on commit 0b43ce5

Please sign in to comment.