# Wait for server initialization

To manually trigger and wait for server initialization, use the `initIfNeeded` method:

{% code title="src/lib/getHypertune.ts" %}

```typescript
import { createSource } from '../generated/hypertune'

const hypertuneSource = createSource({
  token: process.env.HYPERTUNE_TOKEN!,
  initDataRefreshIntervalMs: 5_000,
})

export default async function getHypertune() {
  await hypertuneSource.initIfNeeded()

  return hypertuneSource.root({
    args: {
      context: {
        environment:
          process.env.NODE_ENV === 'development'
            ? 'development'
            : 'production',
        user: {
          id: 'e23cc9a8-0287-40aa-8500-6802df91e56a',
          name: 'Example User',
          email: 'user@example.com',
        },
      },
    },
  })
}
```

{% endcode %}

When using `initIfNeeded`, the `initDataRefreshIntervalMs` option specifies the minimum time between initialization requests.

For example, if you set this to `5_000`, `initIfNeeded` will only trigger a new initialization request if the last one was over 5 seconds ago.

So you can await `initIfNeeded` on every backend request to ensure flag values are fresh while minimizing network latency and bandwidth.

This is particularly useful in [serverless and edge environments](/sdk-reference/serverless-environments.md) like Vercel deployments, Cloudflare Workers, AWS Lambdas, etc, where background SDK tasks like fetching updates aren't guaranteed to execute.

## Check for server initialization

To check for server initialization, use the `getLastInitDataRefreshTime` method:

{% code title="src/components/ClientComponent.tsx" %}

```tsx
import { useHypertune } from '../generated/hypertune.react'

export default function ClientComponent() {
  const hypertune = useHypertune()

  if (!hypertune.getLastInitDataRefreshTime()) {
    return null
  }

  const exampleFlag = hypertune.exampleFlag({ fallback: false })

  return <div>Example Flag: {String(exampleFlag)}</div>
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hypertune.com/sdk-reference/wait-for-server-initialization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
