> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/async/asyncrun.md).

# AsyncRun

Executes the given code asynchronously and returns to you a BoxFuture object which inherits from CompletableFuture.

This way you can create fluent asynchronous code that can be chained and composed.

## Method Signature

```
AsyncRun(callback=[function], executor=[any])
```

### Arguments

| Argument   | Type       | Required | Description                                                                                                                                                              | Default |
| ---------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `callback` | `function` | `true`   | <p>The code to execute asynchronously, this can be a closure<br>or lambda.</p>                                                                                           |         |
| `executor` | `any`      | `false`  | <p>The executor to use for the asynchronous execution. This<br>can be an instance of an Executor class, or the name of a<br>registered executor in the AsyncService.</p> |         |

## Examples

### Execute code asynchronously

Runs the callback in a separate thread and returns a BoxFuture.

```java
future = asyncRun( () => sleep( 100 ) && return "done" );
writeOutput( future.get() );

```

Result: done

### Chain async operations with then()

```java
asyncRun( () => 10 )
    .then( ( v ) => v * 2 )
    .then( ( v ) => v + 5 )
    .thenAccept( ( v ) => writeOutput( v ) );

```

Result: 25

### Using the runAsync() alias

```java
future = runAsync( () => "hello from async" );
writeOutput( future.get() );

```

Result: hello from async

## Related

* [AsyncAll](/boxlang-language/reference/built-in-functions/async/asyncall.md)
* [AsyncAllApply](/boxlang-language/reference/built-in-functions/async/asyncallapply.md)
* [AsyncAny](/boxlang-language/reference/built-in-functions/async/asyncany.md)
* [ExecutorDelete](/boxlang-language/reference/built-in-functions/async/executordelete.md)
* [ExecutorGet](/boxlang-language/reference/built-in-functions/async/executorget.md)
* [ExecutorHas](/boxlang-language/reference/built-in-functions/async/executorhas.md)
* [ExecutorList](/boxlang-language/reference/built-in-functions/async/executorlist.md)
* [ExecutorNew](/boxlang-language/reference/built-in-functions/async/executornew.md)
* [ExecutorShutdown](/boxlang-language/reference/built-in-functions/async/executorshutdown.md)
* [ExecutorStatus](/boxlang-language/reference/built-in-functions/async/executorstatus.md)
* [FutureNew](/boxlang-language/reference/built-in-functions/async/futurenew.md)
* [IsInThread](/boxlang-language/reference/built-in-functions/async/isinthread.md)
* [isThreadAlive](/boxlang-language/reference/built-in-functions/async/isthreadalive.md)
* [IsThreadInterrupted](/boxlang-language/reference/built-in-functions/async/isthreadinterrupted.md)
* [RunAsync](/boxlang-language/reference/built-in-functions/async/runasync.md)
* [ThreadCurrent](/boxlang-language/reference/built-in-functions/async/threadcurrent.md)
* [ThreadInterrupt](/boxlang-language/reference/built-in-functions/async/threadinterrupt.md)
* [ThreadJoin](/boxlang-language/reference/built-in-functions/async/threadjoin.md)
* [ThreadNew](/boxlang-language/reference/built-in-functions/async/threadnew.md)
* [ThreadTerminate](/boxlang-language/reference/built-in-functions/async/threadterminate.md)


---

# 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://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/async/asyncrun.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.
