> For the complete documentation index, see [llms.txt](https://jakekwak.gitbook.io/nestjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jakekwak.gitbook.io/nestjs/fundamentals/asynchronous-providers.md).

# Asynchronous providers

## Asynchronous providers

일부 **비동기 작업**이 완료 될 때까지 (예: 데이터베이스와의 연결이 설정 될 때까지) 응용 프로그램 시작을 지연해야하는 경우 비동기 공급자 사용을 고려해야 합니다. `비동기` 공급자를 만들기 위해 `useFactory`를 사용합니다. 팩토리는 `Promise`를 반환해야 합니다 (따라서 `async` 기능도 적합합니다).

```typescript
{
  provide: 'ASYNC_CONNECTION',
  useFactory: async () => {
    const connection = await createConnection(options);
    return connection;
  },
}
```

> info **힌트** 사용자 정의 제공자 구문에 대해 자세히 알아보십시오 [여기](https://app.gitbook.com/fundamentals/custom-providers).

## Injection

비동기 프로바이더는 토큰 (위의 경우 `ASYNC_CONNECTION`토큰)에 의해 다른 컴포넌트에 간단히 주입될 수 있습니다. 비동기 공급자가 **이미 해결**되면 비동기 공급자에 종속된 각 클래스가 인스턴스화됩니다.

위의 예는 데모용입니다. 더 자세한 정보를 원한다면 [여기 참조](https://app.gitbook.com/recipes/sql-typeorm).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://jakekwak.gitbook.io/nestjs/fundamentals/asynchronous-providers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
