Skip to content

Commit 7609a84

Browse files
committed
Cleanup interactions with isRunning and isClosed properties
1 parent dcf6b20 commit 7609a84

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Sources/NIORedis/RedisConnection.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ public final class RedisConnection {
1212
public let channel: Channel
1313

1414
/// Has the connection been closed?
15-
public private(set) var isClosed = Atomic<Bool>(value: false)
15+
public var isClosed: Bool { return _isClosed.load() }
16+
private var _isClosed = Atomic<Bool>(value: false)
1617

17-
deinit { assert(isClosed.load(), "Redis connection was not properly shut down!") }
18+
deinit { assert(_isClosed.load(), "Redis connection was not properly shut down!") }
1819

1920
/// Creates a new connection on the provided channel.
2021
/// - Note: This connection will take ownership of the `Channel` object.
@@ -27,7 +28,7 @@ public final class RedisConnection {
2728
/// - Returns: An `EventLoopFuture` that resolves when the connection has been closed.
2829
@discardableResult
2930
public func close() -> EventLoopFuture<Void> {
30-
guard isClosed.exchange(with: true) else { return channel.eventLoop.makeSucceededFuture(result: ()) }
31+
guard _isClosed.exchange(with: true) else { return channel.eventLoop.makeSucceededFuture(result: ()) }
3132

3233
let promise = channel.eventLoop.makePromise(of: Void.self)
3334

@@ -53,7 +54,7 @@ public final class RedisConnection {
5354
/// - arguments: The arguments to be sent with the command.
5455
/// - Returns: An `EventLoopFuture` that will resolve with the Redis command response.
5556
public func command(_ command: String, arguments: [RESPValue] = []) -> EventLoopFuture<RESPValue> {
56-
guard !isClosed.load() else {
57+
guard !_isClosed.load() else {
5758
return channel.eventLoop.makeFailedFuture(error: RedisError.connectionClosed)
5859
}
5960

Sources/NIORedis/RedisDriver.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public final class RedisDriver {
1414
private let ownershipModel: ThreadOwnershipModel
1515
private let eventLoopGroup: EventLoopGroup
1616

17-
private let isRunning = Atomic<Bool>(value: true)
17+
/// Is the driver available for operations?
18+
public var isRunning: Bool { return _isRunning.load() }
19+
private let _isRunning = Atomic<Bool>(value: true)
1820

19-
deinit { assert(!isRunning.load(), "Redis driver was not properly shut down!") }
21+
deinit { assert(!_isRunning.load(), "Redis driver was not properly shut down!") }
2022

2123
/// Creates a driver instance to create connections to a Redis.
2224
/// - Important: Call `terminate()` before deinitializing to properly cleanup resources.
@@ -35,7 +37,7 @@ public final class RedisDriver {
3537
/// Handles the proper shutdown of managed resources.
3638
/// - Important: This method should always be called, even when running in `.eventLoopGroup` mode.
3739
public func terminate() throws {
38-
guard isRunning.exchange(with: false) else { return }
40+
guard _isRunning.exchange(with: false) else { return }
3941

4042
switch ownershipModel {
4143
case .internal: try self.eventLoopGroup.syncShutdownGracefully()

0 commit comments

Comments
 (0)