NotificationManager

Manages asynchronous notifications (LISTEN / NOTIFY) for a specific database session.

This manager provides methods to subscribe to and unsubscribe from PostgreSQL notification channels, emit new notifications, and start listener loops to receive incoming messages via a Flow.

Constructors

Link copied to clipboard
internal constructor(session: OctaviusSessionImpl)

Properties

Link copied to clipboard
val messages: SharedFlow<PgNotification>

A SharedFlow of asynchronous notifications (LISTEN/NOTIFY) received from the database.

Functions

Link copied to clipboard
fun listen(vararg channels: String)

Registers this connection to listen for notifications on the specified channel(s).

Link copied to clipboard
fun notify(channel: String, payload: String? = null)

Sends a notification to the specified channel, optionally with a payload string.

Link copied to clipboard
internal fun releaseSubscriptions()

Drops whatever this session subscribed to, if anything.

Link copied to clipboard
suspend fun startInterruptibleListenerLoop(dispatcher: CoroutineDispatcher? = null)

Starts a listener loop that blocks indefinitely. When the coroutine is cancelled, it simply closes the socket.

Link copied to clipboard
suspend fun startPollingListenerLoop(pollTimeoutMs: Int = 500, dispatcher: CoroutineDispatcher? = null)

Starts a listener loop using active polling with a socket timeout. When the coroutine is cancelled, the loop exits gracefully without closing the underlying database connection, allowing it to be reused.

Link copied to clipboard
fun unlisten(vararg channels: String)

Stops listening for notifications on the specified channel(s).

Link copied to clipboard

Stops listening for all notifications on this connection.