WaitForNotification waits for a LISTEN/NOTIFY message to be received. It returns an error if a notification was not received.
(ctx context.Context)
| 1161 | // WaitForNotification waits for a LISTEN/NOTIFY message to be received. It returns an error if a notification was not |
| 1162 | // received. |
| 1163 | func (pgConn *PgConn) WaitForNotification(ctx context.Context) error { |
| 1164 | if err := pgConn.lock(); err != nil { |
| 1165 | return err |
| 1166 | } |
| 1167 | defer pgConn.unlock() |
| 1168 | |
| 1169 | if ctx != context.Background() { |
| 1170 | select { |
| 1171 | case <-ctx.Done(): |
| 1172 | return newContextAlreadyDoneError(ctx) |
| 1173 | default: |
| 1174 | } |
| 1175 | |
| 1176 | pgConn.contextWatcher.Watch(ctx) |
| 1177 | defer pgConn.contextWatcher.Unwatch() |
| 1178 | } |
| 1179 | |
| 1180 | for { |
| 1181 | msg, err := pgConn.receiveMessage() |
| 1182 | if err != nil { |
| 1183 | return normalizeTimeoutError(ctx, err) |
| 1184 | } |
| 1185 | |
| 1186 | if _, ok := msg.(*pgproto3.NotificationResponse); ok { |
| 1187 | return nil |
| 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | // Exec executes SQL via the PostgreSQL simple query protocol. SQL may contain multiple queries. Execution is |
| 1193 | // implicitly wrapped in a transaction unless a transaction is already in progress or SQL contains transaction control |