Skip to content

Commit 4361a02

Browse files
authored
Add internal _send function that returns RESPToken (#91)
1 parent f736fa6 commit 4361a02

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Sources/Valkey/Connection/ValkeyConnection.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,20 @@ public final actor ValkeyConnection: ValkeyConnectionProtocol, Sendable {
115115
/// - Returns: The command response as defined in the ValkeyCommand
116116
@inlinable
117117
public func send<Command: ValkeyCommand>(command: Command) async throws -> Command.Response {
118+
let result = try await self._send(command: command)
119+
return try .init(fromRESP: result)
120+
}
121+
122+
@inlinable
123+
func _send<Command: ValkeyCommand>(command: Command) async throws -> RESPToken {
118124
let requestID = Self.requestIDGenerator.next()
119125
return try await withTaskCancellationHandler {
120126
if Task.isCancelled {
121127
throw ValkeyClientError(.cancelled)
122128
}
123-
let result = try await withCheckedThrowingContinuation { continuation in
129+
return try await withCheckedThrowingContinuation { continuation in
124130
self.channelHandler.write(command: command, continuation: continuation, requestID: requestID)
125131
}
126-
return try .init(fromRESP: result)
127132
} onCancel: {
128133
self.cancel(requestID: requestID)
129134
}

Sources/Valkey/ValkeyClient.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,16 @@ extension ValkeyClient {
155155

156156
/// Extend ValkeyClient so we can call commands directly from it
157157
extension ValkeyClient: ValkeyConnectionProtocol {
158+
@inlinable
158159
public func send<Command: ValkeyCommand>(command: Command) async throws -> Command.Response {
159-
try await self.withConnection {
160-
try await $0.send(command: command)
160+
let token = try await self._send(command)
161+
return try Command.Response(fromRESP: token)
162+
}
163+
164+
@inlinable
165+
func _send<Command: ValkeyCommand>(_ command: Command) async throws -> RESPToken {
166+
try await self.withConnection { connection in
167+
try await connection._send(command: command)
161168
}
162169
}
163170
}

0 commit comments

Comments
 (0)