The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/lib/onStartup.ts

25 lines
490 B

type StartupCallback = () => Promise<void>;
const callbackList: StartupCallback[] = [];
let hasStarted = false;
export const onStartup = (cb: StartupCallback): void => {
if (hasStarted) {
return Promise.await(cb());
}
callbackList.push(cb);
};
const runCallbacks = async (): Promise<void> => {
for await (const cb of callbackList) {
await cb();
}
callbackList.splice(0, callbackList.length);
};
Meteor.startup(() => {
hasStarted = true;
Promise.await(runCallbacks());
});