egg
Version:
A web application framework for Node.js
43 lines • 1.67 kB
TypeScript
import { Application } from "./application.js";
import { StartEggOptions } from "./start.js";
//#region src/lib/snapshot.d.ts
/**
* Build a V8 startup snapshot of an egg application.
*
* Call this from the snapshot entry script passed to
* `node --snapshot-blob=snapshot.blob --build-snapshot snapshot_entry.js`.
*
* It loads all metadata (plugins, configs, extensions, services, controllers,
* router, tegg modules), triggers snapshotWillSerialize hooks to clean up
* non-serializable resources (file handles, timers, process listeners),
* then registers a V8 deserialize callback to stash the app for later restore.
*
* Example snapshot entry script:
* ```ts
* import { buildSnapshot } from 'egg';
* await buildSnapshot({ baseDir: __dirname });
* ```
*
* Example restoring from snapshot:
* ```ts
* import { restoreSnapshot } from 'egg';
* const app = await restoreSnapshot();
* // app is fully restored with resources recreated, ready for server creation
* ```
*/
export declare function buildSnapshot(options?: Pick<StartEggOptions, "framework" | "baseDir" | "env" | "plugins">): Promise<void>;
/**
* Restore an egg application from a V8 startup snapshot.
*
* Triggers the snapshotDidDeserialize lifecycle hooks to recreate
* non-serializable resources (messenger, loggers, process listeners)
* and resumes the lifecycle from configDidLoad through didReady.
*
* Returns the fully restored Application instance with all metadata
* pre-loaded (plugins, configs, extensions, services, controllers, router).
*/
export declare function restoreSnapshot(): Promise<Application>;
declare global {
var __egg_snapshot_app: unknown;
}
//#endregion