You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for receiving and dispatching NotificationResponse messages (vapor#60)
* Add support for receiving and dispatching NotificationResponse messages
* Conform to a less powerful protocol
* Handle notifications by inserting channel handler
* Appropriately filter based on channel
* Swap notification & context parameters in callback
* Put PostgresNotificationHandlers at end
* Explicit "self."
* Log parse failures rather than passing down the chain
* Documentation for PostgresListenContext
* Rename listen to addListener
* Add documentation for addListener
/// Context for receiving NotificationResponse messages on a connection, used for PostgreSQL's `LISTEN`/`NOTIFY` support.
5
+
publicfinalclassPostgresListenContext{
6
+
varstopper:(()->Void)?
7
+
8
+
/// Detach this listener so it no longer receives notifications. Other listeners, including those for the same channel, are unaffected. `UNLISTEN` is not sent; you are responsible for issuing an `UNLISTEN` query yourself if it is appropriate for your application.
9
+
publicfunc stop(){
10
+
stopper?()
11
+
stopper =nil
12
+
}
13
+
}
14
+
15
+
extensionPostgresConnection{
16
+
/// Add a handler for NotificationResponse messages on a certain channel. This is used in conjunction with PostgreSQL's `LISTEN`/`NOTIFY` support: to listen on a channel, you add a listener using this method to handle the NotificationResponse messages, then issue a `LISTEN` query to instruct PostgreSQL to begin sending NotificationResponse messages.
// Slightly complicated: We need to dispatch downstream _before_ we handle the notification ourselves, because the notification handler could try to stop the listen, which removes ourselves from the pipeline and makes fireChannelRead not work any more.
Copy file name to clipboardExpand all lines: Sources/PostgresNIO/Connection/PostgresRequest.swift
+2
Original file line number
Diff line number
Diff line change
@@ -89,6 +89,8 @@ final class PostgresRequestHandler: ChannelDuplexHandler {
89
89
}catch{
90
90
self.errorCaught(context: context, error: error)
91
91
}
92
+
// Regardless of error, also pass the message downstream; this is necessary for PostgresNotificationHandler (which is appended at the end) to receive notifications
0 commit comments