forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresConnection.swift
44 lines (35 loc) · 1.02 KB
/
PostgresConnection.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Foundation
import Logging
public final class PostgresConnection {
let channel: Channel
public var eventLoop: EventLoop {
return self.channel.eventLoop
}
public var closeFuture: EventLoopFuture<Void> {
return channel.closeFuture
}
public var logger: Logger
private var didClose: Bool
public var isClosed: Bool {
return !self.channel.isActive
}
init(channel: Channel, logger: Logger) {
self.channel = channel
self.logger = logger
self.didClose = false
}
public func close() -> EventLoopFuture<Void> {
guard !self.didClose else {
return self.eventLoop.makeSucceededFuture(())
}
self.didClose = true
if !self.isClosed {
return self.channel.close(mode: .all)
} else {
return self.eventLoop.makeSucceededFuture(())
}
}
deinit {
assert(self.didClose, "PostgresConnection deinitialized before being closed.")
}
}