# HG changeset patch # User Matthew Wild # Date 1680346790 -3600 # Node ID 46c05c2e34f783c52718378919d457e7af683402 # Parent 06453c56414182dd1a60f01d5fee19d5dc89ae38 moduleapi: Add module:once() to execute a function after module load/startup It is a common pattern for modules to do something like check for prosody.start_time, and execute code immediately if it is present, or wait for the server-started event if it isn't yet. For example, this allows you to run code after all other modules/hosts have been loaded, that are going to be loaded. Such code can now be replaced with a simple call to this method. diff -r 06453c564141 -r 46c05c2e34f7 core/moduleapi.lua --- a/core/moduleapi.lua Sat Apr 01 11:56:38 2023 +0100 +++ b/core/moduleapi.lua Sat Apr 01 11:59:50 2023 +0100 @@ -693,4 +693,9 @@ end end +-- Execute a function, once, but only after startup is complete +function api:once(f) + return prosody.started:next(f); +end + return api;