Copyright | (c) 2020 Jonathan Fischoff (c) 2016 Moritz Kiefer (c) 2011-2015 Leon P Smith (c) 2012 Joey Adams |
---|---|
License | BSD3 |
Maintainer | Moritz Kiefer <[email protected]> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Database.PostgreSQL.LibPQ.Notify
Contents
Description
Support for receiving asynchronous notifications via PostgreSQL's Listen/Notify mechanism. See http://www.postgresql.org/docs/9.4/static/sql-notify.html for more information.
Note that on Windows, getNotification
currently uses a polling loop
of 1 second to check for more notifications, due to some inadequacies
in GHC's IO implementation and interface on that platform. See GHC
issue #7353 for more information. While this workaround is less than
ideal, notifications are still better than polling the database directly.
Notifications do not create any extra work for the backend, and are
likely cheaper on the client side as well.
http://hackage.haskell.org/trac/ghc/ticket/7353
PostgreSQL notifications support using the same connection for sending and receiving notifications.
However this implementation cannot support this usage pattern.
This implementation favors low latency by utilizing socket read notifications. However a consequence of this implementation choice is the connection used to wait for the notification cannot be used for anything else.
Synopsis
- getNotification :: Connection -> IO (Either IOError Notify)
- getNotificationWithConfig :: Config -> Connection -> IO (Either IOError Notify)
- defaultConfig :: Config
- data Config = Config {
- startLoop :: IO ()
- beforeWait :: IO ()
Documentation
Arguments
:: Connection | The connection. The connection cannot be used for anything else while waiting on the notification or this call might never return. |
-> IO (Either IOError Notify) |
Returns a single notification. If no notifications are
available, getNotification
blocks until one arrives.
The connection passed in cannot be used for anything else while waiting on the notification or this call might never return.
Note that PostgreSQL does not deliver notifications while a connection is inside a transaction.
Advanced API
getNotificationWithConfig Source #
Arguments
:: Config |
|
-> Connection | The connection. The connection cannot be used for anything else while waiting on the notification or this call might never return. |
-> IO (Either IOError Notify) |
Returns a single notification. If no notifications are
available, getNotificationWithConfig
blocks until one arrives.
Unlike getNotification
, getNotificationWithConfig
takes in an
additional Config
parameter provides event hooks for operational insight.
The connection passed in cannot be used for anything else while waiting on the notification or this call might never return.
Note that PostgreSQL does not deliver notifications while a connection is inside a transaction.
defaultConfig :: Config Source #
Default configuration
Options for controlling and instrumenting the behavior of getNotificationWithConfig
Constructors
Config | |
Fields
|