Skip to content

Commit 6a9c284

Browse files
yim-leernro
andauthored
allow setting per-statement request timeout (#9)
Co-authored-by: Rick Newton-Rogers <[email protected]>
1 parent f42a51d commit 6a9c284

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Sources/CassandraClient/Statement.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ extension CassandraClient {
8181
if let consistency = options.consistency {
8282
try checkResult { cass_statement_set_consistency(self.rawPointer, consistency.cassConsistency) }
8383
}
84+
85+
if let requestTimeout = options.requestTimeout {
86+
try checkResult { cass_statement_set_request_timeout(self.rawPointer, requestTimeout) }
87+
}
8488
}
8589

8690
func setPagingSize(_ pagingSize: Int32) throws {
@@ -118,13 +122,21 @@ extension CassandraClient {
118122
public struct Options: CustomStringConvertible {
119123
/// Sets the statement's consistency level. Default is `.localOne`.
120124
public var consistency: CassandraClient.Consistency?
125+
/// Sets the statement's request timeout in milliseconds. Default is `CASS_UINT64_MAX`
126+
public var requestTimeout: UInt64?
121127

122-
public init(consistency: CassandraClient.Consistency? = .none) {
128+
public init(consistency: CassandraClient.Consistency? = nil, requestTimeout: UInt64? = nil) {
123129
self.consistency = consistency
130+
self.requestTimeout = requestTimeout
124131
}
125132

126133
public var description: String {
127-
"Options { consistency: \(String(describing: self.consistency)) }"
134+
"""
135+
Options {
136+
consistency: \(String(describing: self.consistency)),
137+
requestTimeout: \(String(describing: self.requestTimeout))
138+
}
139+
"""
128140
}
129141
}
130142
}

Tests/CassandraClientTests/CassandraClientTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ final class Tests: XCTestCase {
194194
let tableName = "test_\(DispatchTime.now().uptimeNanoseconds)"
195195
XCTAssertNoThrow(try self.cassandraClient.run("create table \(tableName) (id int primary key, data text);").wait())
196196

197-
var options = CassandraClient.Statement.Options()
198-
options.consistency = .localQuorum
197+
let options = CassandraClient.Statement.Options(consistency: .localQuorum)
199198

200199
let count = Int.random(in: 5000 ... 6000)
201200
var futures = [EventLoopFuture<Void>]()

0 commit comments

Comments
 (0)