actionhero Initializer的优先级
actionhero 的Initializer 是包含了优先级的,对于一些场景下我们是需要关注的
参考定义
src/classes/initializer.ts
export abstract class Initializer {
/**The name of the Initializer. */
name: string;
/**What order should this Initializer load at (Default: 1000, Actionhero core methods are < 1000) */
loadPriority?: number;
/**What order should this Initializer start at (Default: 1000, Actionhero core methods are < 1000) */
startPriority?: number;
/**What order should this Initializer stop at (Default: 1000, Actionhero core methods are < 1000) */
stopPriority?: number;
constructor() {
this.name = null;
this.loadPriority = 1000;
this.startPriority = 1000;
this.stopPriority = 1000;
}
启动以及停止使用
src/classes/process.ts
if (!loadInitializerRankings[initializer.loadPriority]) {
loadInitializerRankings[initializer.loadPriority] = [];
}
if (!startInitializerRankings[initializer.startPriority]) {
startInitializerRankings[initializer.startPriority] = [];
}
if (!stopInitializerRankings[initializer.stopPriority]) {
stopInitializerRankings[initializer.stopPriority] = [];
}
if (initializer.loadPriority > 0) {
loadInitializerRankings[initializer.loadPriority].push(
initializeFunction
);
}
if (initializer.startPriority > 0) {
startInitializerRankings[initializer.startPriority].push(
startFunction
);
}
if (initializer.stopPriority > 0) {
stopInitializerRankings[initializer.stopPriority].push(stopFunction);
}
说明
actionhero Initializer 的优先级还是比较重要的,比如开发了好多,有些是有依赖关系的,如果阅读actionhero源码的话也会
发现不少使用此定义的,比如chatroom的
export class ChatRoomInitializer extends Initializer {
constructor() {
super();
this.name = "chatRoom";
this.loadPriority = 520;
this.startPriority = 200;
}