Folks, I have an application that would I would like to react immediately to changes in a PostgreSQL database. I would like to use a combination of TRIGGERs and LISTEN/NOTIFY to achieve this.
I am connecting to my database using: (define (NH . a) (printf "NOTIFICATION: ~s~%" a)) (define pgc (postgresql-connect #:server "my-host" #:user "me" #:database "the-db" #:password "souper secret password" #:notification-handler NH)) Then setting up a “listener” with: (query pgc "LISTEN x") ;; (query pgc "NOTIFY x, 'woo'") ; [1] If I issue a "NOTIFY x;" on an psql prompt... nothing happens. Until I do a database query (even “SELECT 1” is good enough). I can therefore “poll” the database for notifications with: (define (poll-notify) (query pgc "select 1") (sleep 3) (poll-notify)) (thread poll-notify) But I want NH to be called as soon (as possible) as the “NOTIFY” is issued (subject to the caveats in [2]). This either to happen automagically OR by being able to obtain an evt that I can sync on. I can find a place where the handlers are delayed -- I assume due to being inside a transaction or lock -- but I cannot find a handle to anything syncable. Any help would be appreciated. [1] Ironically: if this query is included, NH is called, because the notifcation is posted before the query returns. [2] http://www.postgresql.org/docs/9.4/static/sql-notify.html Regards, Tim -- Tim Brown CEng MBCS <tim.br...@cityc.co.uk> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ City Computing Limited · www.cityc.co.uk City House · Sutton Park Rd · Sutton · Surrey · SM1 2AE · GB T:+44 20 8770 2110 · F:+44 20 8770 2130 ──────────────────────────────────────────────────────────────────────── City Computing Limited registered in London No:1767817. Registered Office: City House, Sutton Park Road, Sutton, Surrey, SM1 2AE VAT No: GB 918 4680 96 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.