> ## Documentation Index
> Fetch the complete documentation index at: https://ugcore.urging.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# UgCore.Lifecycle

> The boot state of ug-core.

<Badge color="purple">Shared</Badge> In your resource, a mirror kept in sync by lifecycle events.

States, in order: `Booting`, `Configured`, `Initializing`, `Starting`, `Ready`, `Stopping`, `Stopped`. States only move forward and MAY be skipped.

## GetState

```lua theme={null}
UgCore.Lifecycle.GetState() -> state
```

<ResponseField name="state" type="UgLifecycleState">The current state, such as `'Ready'`.</ResponseField>

## IsReady

```lua theme={null}
UgCore.Lifecycle.IsReady() -> boolean
```

## HasReached

```lua theme={null}
UgCore.Lifecycle.HasReached(state) -> boolean
```

`false` for states not reached yet and for skipped states.

## On

```lua theme={null}
UgCore.Lifecycle.On(state, handler)
```

<ResponseField name="state" type="UgLifecycleState" required>Raises for unknown states.</ResponseField>
<ResponseField name="handler" type="fun()" required>Runs when ug-core reaches `state`.</ResponseField>

Sticky: runs immediately when the state was already reached. Never runs when the state was skipped. A failing handler is logged and does not stop others.

## Await

```lua theme={null}
UgCore.Lifecycle.Await(state, timeout?) -> reached
```

**MUST run in a thread.**

<ResponseField name="state" type="UgLifecycleState" required />

<ResponseField name="timeout" type="integer">Milliseconds. Waits forever when nil.</ResponseField>
<ResponseField name="reached" type="boolean">`false` on timeout or when the state was skipped.</ResponseField>

```lua theme={null}
CreateThread(function()
    if UgCore.Lifecycle.Await('Ready', 30000) then
        -- safe to use every module
    end
end)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.