Function: createLifecycle()
createLifecycle<
S>(stages):Lifecycle<S[number]>
Defined in: src/utils/lifecycle.ts:298
Defines lifecycle stages, in the order they run, and returns a tag per stage. Modules register hooks under the stage keys with addSingleton; startLifecycle runs them stage by stage.
Reusable modules use the default lifecycle. An app with its own stages passes the result to startLifecycle(app, { lifecycle }).
Type Parameters
S
S extends readonly string[]
Parameters
stages
S
Returns
Lifecycle<S[number]>
Throws
INJECUTE_INVALID_OPTION when there are no stages, or a stage name is empty, repeated, or contains : or ..
Example
ts
export const stages = createLifecycle(['migrate', 'init', 'start', 'ready']);
// a module
c.addSingleton(stages.migrate('schema'), (db) => migrate(db), ['db']);
// the composition root
const running = await startLifecycle(app, { lifecycle: stages });