> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Function: runOnMainThread()

> **runOnMainThread**\<`R`, `Fn` _extends_ (...`args`: `any`\[]) => `R`>(`fn`: `Fn`): (...`args`: `Parameters`\<`Fn`>) => `Promise`\<`R`>

`runOnMainThread` allows triggering main thread functions on the main thread asynchronously.

## Type Parameters

| Type Parameter                              |
| ------------------------------------------- |
| `R`                                         |
| `Fn` _extends_ (...`args`: `any`\[]) => `R` |

## Parameters

| Parameter | Type | Description                             |
| --------- | ---- | --------------------------------------- |
| `fn`      | `Fn` | The main thread functions to be called. |

## Returns

A function. Calling which with the arguments to be passed to the main thread function to trigger it on the main thread. This function returns a promise that resolves to the return value of the main thread function.

(...`args`: `Parameters`\<`Fn`>) => `Promise`\<`R`>

## Example

```ts
import { runOnMainThread } from '@lynx-js/react';

async function someFunction() {
  const fn = runOnMainThread(() => {
    'main thread';
    return 'hello';
  });
  const result = await fn();
}
```
