unsafe extern "C" fn callback(event: pg_sys::XactEvent, _arg: *mut ::std::os::raw::c_void) {
        let which_event = PgXactCallbackEvent::translate_pg_event(event);

        let hooks = match which_event {
            // pgx's XactCallbacks are per-transaction, so when the transaction is over
            // (that's either Commit or Abort, which are mutually exclusive), we replace our
            // const XACT_HOOKS with a new, empty Map so that subsequent transactions won't accidentally run
            // these hooks again.
            //
            // Note that we still run any hooks that are registered for these events in this xact
            PgXactCallbackEvent::Commit
            | PgXactCallbackEvent::Abort
            | PgXactCallbackEvent::ParallelCommit
            | PgXactCallbackEvent::ParallelAbort => XACT_HOOKS
                .replace(HashMap::new())
                .expect("XACT_HOOKS was None during Commit/Abort")
                .remove(&which_event),

            // not in a transaction-end event, so just borrow our map
            _ => XACT_HOOKS
                .as_mut()
                .expect("XACT_HOOKS was None")
                .remove(&which_event),
        };

        // if we have a vec of hooks for this event they're consumed here and executed
        // in the order they were registered
        if let Some(hooks) = hooks {
            for hook in hooks.into_iter() {
                // TODO:  do we need to catch panics and do something with them?  They'll cause
                //  the Postgres backend to Abort() if we're handling XactEvent::Commit/Abort events

                // effectively 'take' the hook from the internal RefCell
                if let Some(hook) = hook.replace(None) {
                    // and execute it under guard for proper panic/elog(ERROR) handling
                    crate::guard::guard(hook.0);
                }
            }
        }
    }
// internal function that we register as an XactCallback
internal function that we register as an XactCallback
internal function that we register as an XactCallback
unsafe extern "C" fn callback(event: pg_sys::XactEvent, _arg: *mut ::std::os::raw::c_void) {
        let which_event = PgXactCallbackEvent::translate_pg_event(event);
        let hooks = match which_event {
            // pgx's XactCallbacks are per-transaction, so when the transaction is over
            // (that's either Commit or Abort, which are mutually exclusive), we replace our
            // const XACT_HOOKS with a new, empty Map so that subsequent transactions won't accidentally run
            // these hooks again.
            //
            // Note that we still run any hooks that are registered for these events in this xact
            PgXactCallbackEvent::Commit
            | PgXactCallbackEvent::Abort
            | PgXactCallbackEvent::ParallelCommit
            | PgXactCallbackEvent::ParallelAbort => XACT_HOOKS
                .replace(HashMap::new())
                .expect("XACT_HOOKS was None during Commit/Abort")
                .remove(&which_event),
            // not in a transaction-end event, so just borrow our map
            _ => XACT_HOOKS
                .as_mut()
                .expect("XACT_HOOKS was None")
                .remove(&which_event),
        };
        // if we have a vec of hooks for this event they're consumed here and executed
        // in the order they were registered
        if let Some(hooks) = hooks {
            for hook in hooks.into_iter() {
                // TODO:  do we need to catch panics and do something with them?  They'll cause
                //  the Postgres backend to Abort() if we're handling XactEvent::Commit/Abort events
                // effectively 'take' the hook from the internal RefCell
                if let Some(hook) = hook.replace(None) {
                    // and execute it under guard for proper panic/elog(ERROR) handling
                    crate::guard::guard(hook.0);
                }
            }
        }
    }
unsafe extern " " fn callback ( event : pg_sys :: XactEvent , _arg : * mut :: std :: os :: raw :: c_void ) { let which_event = PgXactCallbackEvent :: translate_pg_event ( event ) ; let hooks = match which_event { // pgx's XactCallbacks are per-transaction, so when the transaction is over // (that's either Commit or Abort, which are mutually exclusive), we replace our // const XACT_HOOKS with a new, empty Map so that subsequent transactions won't accidentally run // these hooks again. // // Note that we still run any hooks that are registered for these events in this xact PgXactCallbackEvent :: Commit | PgXactCallbackEvent :: Abort | PgXactCallbackEvent :: ParallelCommit | PgXactCallbackEvent :: ParallelAbort => XACT_HOOKS . replace ( HashMap :: new ( ) ) . expect ( " " ) . remove ( & which_event ) , // not in a transaction-end event, so just borrow our map _ => XACT_HOOKS . as_mut ( ) . expect ( " " ) . remove ( & which_event ) , } ; // if we have a vec of hooks for this event they're consumed here and executed // in the order they were registered if let Some ( hooks ) = hooks { for hook in hooks . into_iter ( ) { // TODO:  do we need to catch panics and do something with them?  They'll cause //  the Postgres backend to Abort() if we're handling XactEvent::Commit/Abort events // effectively 'take' the hook from the internal RefCell if let Some ( hook ) = hook . replace ( None ) { // and execute it under guard for proper panic/elog(ERROR) handling crate :: guard :: guard ( hook . 0 ) ; } } } }
internal function that we register as an XactCallback
internal function that we register as an XactCallback
event
pg_sys::XactEvent
_arg
*mut ::std::os::raw::c_void
event
pg_sys::XactEvent
_arg
*mut ::std::os::raw::c_void