# CoordinatedStartup

`class` in `services` · v0.8.2

<https://docs.seedcord.org/packages/services/0.8.2/classes/coordinated-startup>

Manages bot startup lifecycle with ordered phases

Coordinates initialization of all bot components in a predictable sequence. Tasks are executed within their designated phases to ensure proper dependency order.

```ts
class CoordinatedStartup extends CoordinatedLifecycle<
    StartupPhase,
    CoordinatedStartupEvents
>
```

## Constructors

### constructor

```ts
CoordinatedStartup()
```

Constructs a new instance of the `CoordinatedStartup` class

## Properties

### isReady

```ts
public get isReady(): boolean
```

Check if startup has completed

### isRunning

```ts
public get isRunning(): boolean
```

Check if startup is currently running

### logger

```ts
protected readonly logger: Logger
```

### phaseEnum

```ts
protected readonly phaseEnum: Record<number, string>
```

### phaseOrder

```ts
protected readonly phaseOrder: TPhase[]
```

### tasksMap

```ts
protected readonly tasksMap: Map<TPhase, LifecycleTask[]>
```

## Methods

### abort

```ts
public abort(): void
```

Aborts the startup sequence if it is currently running.

### addListener

```ts
addListener<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Alias of [`on`](/packages/services/0.8.2/classes/strict-event-emitter#on) for compatibility with Node.js EventEmitter APIs.

### addTask

```ts
public addTask(
    phase: StartupPhase,
    taskName: string,
    task: () => Promise<void>,
    timeoutMs?: number
): void
```

Adds a task to a specific startup phase with timeout.

### canAddTask

```ts
protected canAddTask(): boolean
```

### canRemoveTask

```ts
protected canRemoveTask(): boolean
```

### emit

```ts
emit<TEventKey>(
    event: TEventKey,
    args: TEvents[TEventKey]
): boolean
```

Emits an event with the strictly typed argument tuple for the event name.

### eventNamesTyped

```ts
eventNamesTyped(): SEEventKey<TEvents>[]
```

Returns the list of event names known to the emitter with the mapped key type.

### executeTasksInPhase

```ts
protected async executeTasksInPhase(
    phase: StartupPhase,
    tasks: LifecycleTask[]
): Promise<PromiseSettledResult<void>[]>
```

### getTaskType

```ts
protected getTaskType(): string
```

### listenerCountTyped

```ts
listenerCountTyped<TEventKey>(event: TEventKey): number
```

Counts listeners for an event without widening the return type of listenerCount.

### listeners

```ts
listeners<TEventKey>(
    event: TEventKey
): ((...args: TEvents[TEventKey]) => void)[]
```

Retrieves the listener list for a given event with the correct tuple signature.

### off

```ts
off<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Removes a previously registered listener for the given event.

### on

```ts
on<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Registers a persistent listener with tuple-safe arguments for the given event.

### once

```ts
once<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Registers a one time listener that is removed after the first invocation.

### removeListener

```ts
removeListener<TEventKey>(
    event: TEventKey,
    listener: (...args: TEvents[TEventKey]) => void
): this
```

Alias of [`off`](/packages/services/0.8.2/classes/strict-event-emitter#off) for compatibility with Node.js EventEmitter APIs.

### removeTask

```ts
removeTask(
    phase: TPhase,
    taskName: string
): boolean
```

Removes a lifecycle task from a specific phase.

### run

```ts
public async run(): Promise<void>
```

Executes the coordinated startup sequence.

Runs all registered tasks across startup phases in the correct order. Each phase completes before the next phase begins. Tasks within a phase are executed sequentially to maintain predictable initialization.

### runPhase

```ts
protected async runPhase(phase: TPhase): Promise<void>
```

Run all tasks in a specific phase

### runTaskWithTimeout

```ts
protected async runTaskWithTimeout(
    phase: StartupPhase,
    task: LifecycleTask
): Promise<void>
```

### waitFor

```ts
async waitFor<TEventKey>(
    event: TEventKey,
    opts?: { signal?: AbortSignal; timeoutMs?: number }
): Promise<TEvents[TEventKey]>
```

Waits for an event to be emitted, resolving with the listener arguments tuple once triggered. Supports optional abort signals and timeouts for cancellation semantics.
