# async.all (Shared)

> Runs every function in the list in its own thread, all at once, and makes the current thread wait until they have all ended.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Timers and async
- **URL**: https://wiki.mymp.gg/en/async.all

## Syntax

```lua
any async.all(table tasks)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `tasks` | `table` | A list of functions. Entries that are not functions go straight into the result. |

## Returns

One value per list entry, in the same order: the first value each function returned, or the entry itself if it is not a function. Only works inside an async thread. Outside one, it logs an error and returns `false`.

## Example

```lua
async.thread(function()
    local first, second = async.all({
        function()
            async.wait(300)
            return "first"
        end,
        function()
            async.wait(100)
            return "second"
        end,
    })
    outputDebugString(first .. " " .. second)
end)
```

### Note

If one of the functions raises an error, it becomes an error in the waiting thread, and the others' results are lost.

## See also

- [async.promise (Shared)](https://wiki.mymp.gg/en/async.promise.md): Runs handler(resolve, reject) in a new thread and makes the current thread wait until it calls resolve or reject. Meant for waiting on a function that answers through a callback.
- [async.map (Shared)](https://wiki.mymp.gg/en/async.map.md): Calls handler(value, key) for every entry of the table, in pairs order, and gathers the results that are not nil into a list. The handler may pause with async.wait.
- [async.thread (Shared)](https://wiki.mymp.gg/en/async.thread.md): Runs a function in a new async thread, right away. The call returns when the function ends or first pauses, as with async.wait.
