# CoordinatedLifecycle

`class` in `core` · v0.4.1

<https://docs.seedcord.org/packages/core/0.4.1/classes/coordinated-lifecycle>

```ts
abstract class CoordinatedLifecycle<TPhase extends number>
```

## Constructors

### constructor

```ts
protected CoordinatedLifecycle(
    loggerName: string,
    phaseOrder: TPhase[],
    phaseEnum: Record<number, string>
)
```

Constructs a new instance of the `CoordinatedLifecycle` class

## Properties

### 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

### addTask

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

### canAddTask

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

### canRemoveTask

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

### executeTasksInPhase

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

### getTaskType

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

### isAborted

```ts
protected isAborted(): boolean
```

### removeTask

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

### runPhase

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

### runTaskWithTimeout

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