Skip to content

Commit

Permalink
Revert "Sendable Take 2 (#136)"
Browse files Browse the repository at this point in the history
This reverts commit a8f3ec8.
  • Loading branch information
Joannis committed May 25, 2023
1 parent a8f3ec8 commit 0ba2f8a
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 233 deletions.
14 changes: 0 additions & 14 deletions .api-breakage/allowlist-branch-sendable-take-2.txt

This file was deleted.

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
52 changes: 22 additions & 30 deletions Sources/WebSocketKit/Concurrency/WebSocket+Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,44 @@ extension WebSocket {
try await close(code: code).get()
}

@preconcurrency 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)
}
}
}

@preconcurrency 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)
}
}
}

@preconcurrency 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)
}
}
}

@preconcurrency 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)
}
}
}

@preconcurrency public static func connect(
public static func connect(
to url: String,
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 @@ -100,12 +92,12 @@ extension WebSocket {
).get()
}

@preconcurrency public static func connect(
public static func connect(
to url: URL,
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 @@ -120,7 +112,7 @@ extension WebSocket {
).get()
}

@preconcurrency public static func connect(
public static func connect(
scheme: String = "ws",
host: String,
port: Int = 80,
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
15 changes: 5 additions & 10 deletions Sources/WebSocketKit/WebSocket+Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ extension WebSocket {
/// - eventLoopGroup: Event loop group to be used by the WebSocket client.
/// - onUpgrade: An escaping closure to be executed after the upgrade is completed by `NIOWebSocketClientUpgrader`.
/// - Returns: An future which completes when the connection to the WebSocket server is established.
@preconcurrency
public static func connect(
to url: String,
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 All @@ -41,13 +40,12 @@ extension WebSocket {
/// - eventLoopGroup: Event loop group to be used by the WebSocket client.
/// - onUpgrade: An escaping closure to be executed after the upgrade is completed by `NIOWebSocketClientUpgrader`.
/// - Returns: An future which completes when the connection to the WebSocket server is established.
@preconcurrency
public static func connect(
to url: URL,
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 @@ -76,7 +74,6 @@ extension WebSocket {
/// - eventLoopGroup: Event loop group to be used by the WebSocket client.
/// - onUpgrade: An escaping closure to be executed after the upgrade is completed by `NIOWebSocketClientUpgrader`.
/// - Returns: An future which completes when the connection to the WebSocket server is established.
@preconcurrency
public static func connect(
scheme: String = "ws",
host: String,
Expand All @@ -86,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 @@ -119,7 +116,6 @@ extension WebSocket {
/// - eventLoopGroup: Event loop group to be used by the WebSocket client.
/// - onUpgrade: An escaping closure to be executed after the upgrade is completed by `NIOWebSocketClientUpgrader`.
/// - Returns: An future which completes when the connection to the origin server is established.
@preconcurrency
public static func connect(
scheme: String = "ws",
host: String,
Expand All @@ -133,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 @@ -166,7 +162,6 @@ extension WebSocket {
/// - eventLoopGroup: Event loop group to be used by the WebSocket client.
/// - onUpgrade: An escaping closure to be executed after the upgrade is completed by `NIOWebSocketClientUpgrader`.
/// - Returns: An future which completes when the connection to the origin server is established.
@preconcurrency
public static func connect(
to url: String,
headers: HTTPHeaders = [:],
Expand All @@ -176,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 0ba2f8a

Please sign in to comment.