# 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: 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://jakekwak.gitbook.io/nestjs/fundamentals/asynchronous-providers.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.
