postgres=> select * from pg_background_result(67069) as (x text); ERROR: terminating connection due to administrator command CONTEXT: background worker, pid 67069 postgres=>
It'll also want to handle cancellation due to conflict with recovery if you intend it to be used on a standby, probably by making use of procsignal_sigusr1_handler. The rest of the work is done by CHECK_FOR_INTERRUPTS() .
This only matters if it's meant to work on standbys of course. I haven't checked if you write to catalogs or otherwise do non-standby-friendly things.