import { Meta } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Functions/executePromise - Execute Promise or function'/>

# `executePromise`

A robust utility for safely executing and awaiting results from flexible sources. It handles synchronous values, Promises, and functions (both synchronous and asynchronous) by ensuring the final result is always resolved and returned as a Promise.

Under the hood, it leverages `executeFunction` to resolve callables and then ensures that if the result is a `Promise`, it is properly awaited.

**Parameters:**
- `callback: ((...args: any[]) => Promise<T>) | ((...args: any[]) => T) | T` — The source to execute or resolve.
- `...args: any[]` (optional) — Arguments to pass to the function if `callback` is callable.

**Returns:**
`Promise<T>` — A promise that resolves to the final computed or provided value.

```typescript
import { executePromise } from '@dxtmisha/functional-basic'

// 1. Awaiting an async function
const fetchData = async (id: number) => {
  return await fetch(`/api/user/${id}`).then(res => res.json())
}
const user = await executePromise(fetchData, 123)

// 2. Handling a synchronous function
const getName = () => 'John Doe'
const name = await executePromise(getName) // returns Promise resolving to 'John Doe'

// 3. Resolving a static value
const result = await executePromise('Immediate Data')
```
