container->singleton( Shutdown_Handler::class, fn() => new Shutdown_Handler( // Add any terminable tasks to the collection to run on shutdown. // Important: these will run in the order provided. $this->container->get( Config::class ), $this->container->get( Updater::class ), $this->container->get( Batch_Purger::class ), ) ); // Create an action that can be called manually. add_action( 'solidwp/performance/terminate', $this->container->callback( Shutdown_Handler::class, 'handle' ) ); // Run early to get ahead of any potentially bad code that could kill execution. add_action( 'shutdown', static function (): void { do_action( 'solidwp/performance/terminate' ); }, 1 ); // Run this again in case any other code was updated in the shutdown action that could trigger our Terminable tasks. add_action( 'shutdown', static function (): void { do_action( 'solidwp/performance/terminate' ); }, 9999 ); } }