@@ -207,7 +207,7 @@ public final class ValkeyClusterClient: Sendable {
207
207
@inlinable
208
208
public func execute< each Command : ValkeyCommand > (
209
209
_ commands: repeat each Command
210
- ) async throws -> sending ( repeat Result < ( each Command ) . Response, Error > ) {
210
+ ) async -> sending ( repeat Result < ( each Command ) . Response, Error > ) {
211
211
func convert< Response: RESPTokenDecodable > ( _ result: Result < RESPToken , Error > , to: Response . Type ) -> Result < Response , Error > {
212
212
result. flatMap {
213
213
do {
@@ -217,7 +217,7 @@ public final class ValkeyClusterClient: Sendable {
217
217
}
218
218
}
219
219
}
220
- let results = try await self . execute ( [ any ValkeyCommand ] ( commands: repeat each commands) )
220
+ let results = await self . execute ( [ any ValkeyCommand ] ( commands: repeat each commands) )
221
221
var index = AutoIncrementingInteger ( )
222
222
return ( repeat convert( results [ index. next ( ) ] , to: ( each Command) . Response. self) )
223
223
}
@@ -259,40 +259,44 @@ public final class ValkeyClusterClient: Sendable {
259
259
@inlinable
260
260
public func execute(
261
261
_ commands: [ any ValkeyCommand ]
262
- ) async throws -> sending [ Result < RESPToken , Error > ] {
262
+ ) async -> sending [ Result < RESPToken , Error > ] {
263
263
guard commands. count > 0 else { return [ ] }
264
264
// get a list of nodes and the commands that should be run on them
265
- let nodes = try await self . splitCommandsAcrossNodes ( commands: commands)
266
- // if this list has one element, then just run the pipeline on that single node
267
- if nodes. count == 1 {
268
- do {
269
- return try await self . execute ( node: nodes [ nodes. startIndex] . node, commands: commands)
270
- } catch {
271
- return . init( repeating: . failure( error) , count: commands. count)
265
+ do {
266
+ let nodes = try await self . splitCommandsAcrossNodes ( commands: commands)
267
+ // if this list has one element, then just run the pipeline on that single node
268
+ if nodes. count == 1 {
269
+ do {
270
+ return try await self . execute ( node: nodes [ nodes. startIndex] . node, commands: commands)
271
+ } catch {
272
+ return . init( repeating: . failure( error) , count: commands. count)
273
+ }
272
274
}
273
- }
274
- return await withTaskGroup ( of : NodePipelineResult . self ) { group in
275
- // run generated pipelines concurrently
276
- for node in nodes {
277
- let indices = node . commandIndices
278
- group . addTask {
279
- do {
280
- let results = try await self . execute ( node : node . node , commands : IndexedSubCollection ( commands , indices : indices ) )
281
- return . init ( indices : indices , results : results )
282
- } catch {
283
- return NodePipelineResult ( indices : indices , results : . init ( repeating : . failure ( error ) , count : indices . count ) )
275
+ return await withTaskGroup ( of : NodePipelineResult . self ) { group in
276
+ // run generated pipelines concurrently
277
+ for node in nodes {
278
+ let indices = node . commandIndices
279
+ group . addTask {
280
+ do {
281
+ let results = try await self . execute ( node : node . node , commands : IndexedSubCollection ( commands , indices : indices ) )
282
+ return . init ( indices : indices , results : results )
283
+ } catch {
284
+ return NodePipelineResult ( indices : indices , results : . init ( repeating : . failure ( error ) , count : indices . count ) )
285
+ }
284
286
}
285
287
}
286
- }
287
- var results = [ Result < RESPToken , Error > ] ( repeating : . failure ( ValkeyClusterError . pipelinedResultNotReturned ) , count : commands . count )
288
- // get results for each node
289
- while let taskResult = await group . next ( ) {
290
- precondition ( taskResult . indices . count == taskResult. results . count)
291
- for index in 0 ..< taskResult. indices. count {
292
- results [ taskResult . indices [ index ] ] = taskResult . results [ index ]
288
+ var results = [ Result < RESPToken , Error > ] ( repeating : . failure ( ValkeyClusterError . pipelinedResultNotReturned ) , count : commands . count )
289
+ // get results for each node
290
+ while let taskResult = await group . next ( ) {
291
+ precondition ( taskResult. indices . count == taskResult . results . count )
292
+ for index in 0 ..< taskResult. indices . count {
293
+ results [ taskResult. indices [ index ] ] = taskResult . results [ index ]
294
+ }
293
295
}
296
+ return results
294
297
}
295
- return results
298
+ } catch {
299
+ return . init( repeating: . failure( error) , count: commands. count)
296
300
}
297
301
}
298
302
0 commit comments