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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/WebSocketActors/ClientManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ public final actor ClientManager: Manager {
if let remoteNodeID = remoteNodeID {
return remoteNodeID
}
#if DEBUG
return await withCheckedContinuation { continuation in
remoteNodeIDContinuations.append(continuation)
remoteNodeIDContinuations.append(continuation)
}
#else
return await withUnsafeContinuation { continuation in
remoteNodeIDContinuations.append(continuation)
}
#endif
}
}
36 changes: 20 additions & 16 deletions Sources/WebSocketActors/Continuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,34 @@ import Foundation
#if DEBUG
typealias Continuation = CheckedContinuation

@inlinable func withContinuation<T>(function: String = #function,
_ body: (CheckedContinuation<T, Never>) -> Void) async -> T
{
await withCheckedContinuation(function: function, body)
@inlinable func withContinuation<T>(
function: String = #function,
_ body: (CheckedContinuation<T, Never>) -> Void
) async -> T {
await withCheckedContinuation(function: function, body)
}

@inlinable func withThrowingContinuation<T>(function: String = #function,
_ body: (CheckedContinuation<T, Error>) -> Void) async throws -> T
{
try await withCheckedThrowingContinuation(function: function, body)
@inlinable func withThrowingContinuation<T>(
function: String = #function,
_ body: (CheckedContinuation<T, Error>) -> Void
) async throws -> T {
try await withCheckedThrowingContinuation(function: function, body)
}
#else
typealias Continuation = UnsafeContinuation

@inlinable func withContinuation<T>(function: String = #function,
_ body: (UnsafeContinuation<T, Never>) -> Void) async -> T
{
await withUnsafeContinuation(function: function, body)
@inlinable func withContinuation<T>(
function: String = #function,
_ body: (UnsafeContinuation<T, Never>) -> Void
) async -> T {
await withUnsafeContinuation(body)
}

@inlinable func withThrowingContinuation<T>(function: String = #function,
_ body: (UnsafeContinuation<T, Error>) -> Void) async throws -> T
{
try await withUnsafeThrowingContinuation(function: function, body)
@inlinable func withThrowingContinuation<T>(
function: String = #function,
_ body: (UnsafeContinuation<T, Error>) -> Void
) async throws -> T {
try await withUnsafeThrowingContinuation(body)
}
#endif

Expand Down
31 changes: 22 additions & 9 deletions Sources/WebSocketActors/PendingReplies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,28 @@ actor PendingReplies {
}

nonisolated func sendMessage(_ body: @Sendable @escaping (CallID) async throws -> Void) async throws -> Data {
try await withCheckedThrowingContinuation { continuation in
Task {
let callID = await self.expectReply(continuation: continuation)
do {
try await body(callID)
} catch {
try await self.receivedError(callID: callID, error: error)
}
}
#if DEBUG
try await withCheckedThrowingContinuation { continuation in
Task {
let callID = await self.expectReply(continuation: continuation)
do {
try await body(callID)
} catch {
try await self.receivedError(callID: callID, error: error)
}
}
}
#else
try await withUnsafeThrowingContinuation { continuation in
Task {
let callID = await self.expectReply(continuation: continuation)
do {
try await body(callID)
} catch {
try await self.receivedError(callID: callID, error: error)
}
}
}
#endif
}
}
12 changes: 9 additions & 3 deletions Sources/WebSocketActors/ServerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ public final actor ServerManager: Manager {
channel
}
else {
await withCheckedContinuation { continuation in
waitingForChannel.append(continuation)
}
#if DEBUG
await withCheckedContinuation { continuation in
waitingForChannel.append(continuation)
}
#else
await withUnsafeContinuation { continuation in
waitingForChannel.append(continuation)
}
#endif
}
}

Expand Down