forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresConnection.swift
45 lines (36 loc) · 1.4 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
45
import NIOCore
import Logging
import struct Foundation.UUID
public final class PostgresConnection {
let underlying: PSQLConnection
public var eventLoop: EventLoop {
return self.underlying.eventLoop
}
public var closeFuture: EventLoopFuture<Void> {
return self.underlying.channel.closeFuture
}
/// A logger to use in case
public var logger: Logger
/// A dictionary to store notification callbacks in
///
/// Those are used when `PostgresConnection.addListener` is invoked. This only lives here since properties
/// can not be added in extensions. All relevant code lives in `PostgresConnection+Notifications`
var notificationListeners: [String: [(PostgresListenContext, (PostgresListenContext, PostgresMessage.NotificationResponse) -> Void)]] = [:] {
willSet {
self.underlying.channel.eventLoop.preconditionInEventLoop()
}
}
public var isClosed: Bool {
return !self.underlying.channel.isActive
}
init(underlying: PSQLConnection, logger: Logger) {
self.underlying = underlying
self.logger = logger
self.underlying.channel.pipeline.handler(type: PSQLChannelHandler.self).whenSuccess { handler in
handler.notificationDelegate = self
}
}
public func close() -> EventLoopFuture<Void> {
return self.underlying.close()
}
}