# async.cancel (Shared)

> Stops an async thread of this resource. A paused thread ends at once; called from the thread itself, it stops right there.

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

## Syntax

```lua
bool async.cancel(any thread)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `thread` | `any` | A thread from `async.thread` or `async.mutex`. |

## Returns

`true` if it stopped the thread, `false` if it is not an async thread of this resource or was already cancelled.

A cancelled thread no longer runs its `callback`.

## Example

```lua
local countdown = async.thread(function()
    async.wait(10000)
    outputDebugString("time is up")
end)

addCommandHandler("stopcountdown", function()
    async.cancel(countdown)
end)
```

## See also

- [async.status (Shared)](https://wiki.mymp.gg/en/async.status.md): Tells what state an async thread of this resource is in.
- [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.
