diff options
author | Matthew Wild <mwild1@gmail.com> | 2023-04-01 11:59:50 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2023-04-01 11:59:50 +0100 |
commit | 05c67040757bd1c8861caa03755609a42b504ecf (patch) | |
tree | 363a51843e2879e1948b3486125e23773c5b8922 /core | |
parent | 5ce1fe2603abf0e49b396a34bfb3b11a9ccd2e27 (diff) | |
download | prosody-05c67040757bd1c8861caa03755609a42b504ecf.tar.gz prosody-05c67040757bd1c8861caa03755609a42b504ecf.zip |
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.
Diffstat (limited to 'core')
-rw-r--r-- | core/moduleapi.lua | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 00b2ae16..8479284d 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -693,4 +693,9 @@ function api:may(action, context, peek) end end +-- Execute a function, once, but only after startup is complete +function api:once(f) + return prosody.started:next(f); +end + return api; |