One of the cool things PostgreSQL gives you is a simple notification system that you can use to let clients know that something interesting has happened. For instance you can set up rules that broadcast notifications when a table is updated, and client applications can update displays in response. The JDBC driver provides access to this API so I thought I would see what it would look like in doobie.
The program below constructs a Process[ConnectionIO, PGNotification]
that registers for events, polls for them periodically (this is the best we can do with current driver support), and unregisters when the stream terminates for any reason. We use a Transactor
to replace ConnectionIO
with Task
which gives us something we can actually run.
package doobie.example
import doobie.imports._