Comparison

core/moduleapi.lua @ 13015:46c05c2e34f7

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.
author Matthew Wild <mwild1@gmail.com>
date Sat, 01 Apr 2023 11:59:50 +0100
parent 12995:e385f3a06673
child 13016:8aec903ea888
comparison
equal deleted inserted replaced
13014:06453c564141 13015:46c05c2e34f7
691 end 691 end
692 return permit; 692 return permit;
693 end 693 end
694 end 694 end
695 695
696 -- Execute a function, once, but only after startup is complete
697 function api:once(f)
698 return prosody.started:next(f);
699 end
700
696 return api; 701 return api;