backend-{plugin,app}-api: introduce startup hooks and parallelize initialization

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-05-24 15:55:26 +02:00
parent c4e8fefd9f
commit 3bb4158a8a
10 changed files with 256 additions and 76 deletions
+12
View File
@@ -273,6 +273,10 @@ export interface LifecycleService {
hook: LifecycleServiceShutdownHook,
options?: LifecycleServiceShutdownOptions,
): void;
addStartupHook(
hook: LifecycleServiceStartupHook,
options?: LifecycleServiceStartupOptions,
): void;
}
// @public (undocumented)
@@ -283,6 +287,14 @@ export interface LifecycleServiceShutdownOptions {
logger?: LoggerService;
}
// @public (undocumented)
export type LifecycleServiceStartupHook = () => void | Promise<void>;
// @public (undocumented)
export interface LifecycleServiceStartupOptions {
logger?: LoggerService;
}
// @public
export interface LoggerService {
// (undocumented)
@@ -16,6 +16,21 @@
import { LoggerService } from './LoggerService';
/**
* @public
*/
export type LifecycleServiceStartupHook = () => void | Promise<void>;
/**
* @public
*/
export interface LifecycleServiceStartupOptions {
/**
* Optional {@link LoggerService} that will be used for logging instead of the default logger.
*/
logger?: LoggerService;
}
/**
* @public
*/
@@ -35,6 +50,20 @@ export interface LifecycleServiceShutdownOptions {
* @public
*/
export interface LifecycleService {
/**
* Register a function to be called when the backend has been initialized.
*
* @remarks
*
* When used with plugin scope it will wait for the plugin itself to have been initialized.
*
* When used with root scope it will wait for all plugins to have been initialized.
*/
addStartupHook(
hook: LifecycleServiceStartupHook,
options?: LifecycleServiceStartupOptions,
): void;
/**
* Register a function to be called when the backend is shutting down.
*/
@@ -26,6 +26,8 @@ export type { DiscoveryService } from './DiscoveryService';
export type { HttpRouterService } from './HttpRouterService';
export type {
LifecycleService,
LifecycleServiceStartupHook,
LifecycleServiceStartupOptions,
LifecycleServiceShutdownHook,
LifecycleServiceShutdownOptions,
} from './LifecycleService';