# Async

You can have individual methods in a `repository` executed asynchronously, regardless of whether you have passed your own ExecutorService in the MongoManager or not.

This works via the `@Async` annotation, via the desired method in the `Repository`. However, the method only returns a `CompletableFuture` with its value instead of the value directly.

The only thing that changes in the method declaration is the return value, which wraps the previous one in a CompletableFuture.

*Example of using the `@Async`:*

```java
@Collection("customer_repository")
public interface CustomerRepository extends Repository<Customer, UUID>, AsyncRepository<Customer, UUID> {

    // Customer findFirstByFirstName(String firstName);
    @Async
    CompletableFuture<Customer> findFirstByFirstName(String firstName);

    // List<Customer> findManyByCustomerIdIn(List<Integer> customerIdList);
    @Async
    CompletableFuture<List<Customer>> findManyByCustomerIdIn(List<Integer> customerIdList);

    List<Customer> findManyByCustomerIdNotIn(List<Integer> customerIdList);

    // List<Customer> findManyByCustomerIdExists();
    @SortBy(field = "customerId")
    @SortBy(field = "balance", ascending = true)
    @Limit(10)
    @Skip(5)
    @Async
    CompletableFuture<List<Customer>> findManyByCustomerIdExists();

    List<Customer> findManyByCustomerIdNot(int customerId, Sort sort);

    // boolean myTransformedMethod(String street);
    @Transform("existsByStreet")
    @Async
    CompletableFuture<Boolean> myTransformedMethod(String street);

    // boolean updateFieldsByFirstName(String firstName, UpdateBatch updateBatch);
    @Async
    CompletableFuture<Boolean> updateFieldsByFirstName(String firstName, UpdateBatch updateBatch);
}

```


---

# 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://koboo.gitbook.io/en2do/usage/async.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.
