---
name: "canSuspend"
type: command
status: ok
groups: ["Program Flow"]
arma3_since: "1.58"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/canSuspend
revid: 353403
updated: 2024-03-17T20:47:33Z
---

# canSuspend

*Command · Program Flow · Arma 3 v1.58*

## Description

Returns [true](../commands/true.md) if [sleep](../commands/sleep.md), [uiSleep](../commands/uiSleep.md) or [waitUntil](../commands/waitUntil.md) commands can be used in the current scope.
Usually when suspension is not allowed but used, for example when code is executed in [unscheduled environment](../topics/Scheduler.md#unscheduled-environment), the script engine would ignore any suspension command and throw error: "Suspending not allowed in this context".
Using [canSuspend](../commands/canSuspend.md) command allows to detect the correct environment for the code.

> [!NOTE]
> The definition of [scheduled](../topics/Scheduler.md#scheduled-environment) and [unscheduled environment](../topics/Scheduler.md#unscheduled-environment) is not the same as whether or not the script execution can or cannot be suspended.
> For example while .*sqs* and .*fsm* scripts are [scheduled](../topics/Scheduler.md#scheduled_environment) (i.e. added to the [scheduler](../topics/Scheduler.md):
> [diag_activeSQSScripts](../commands/diag_activeSQSScripts.md), [diag_activeMissionFSMs](../commands/diag_activeMissionFSMs.md)), they cannot use [sleep](../commands/sleep.md) or be suspended like [execVM](../commands/execVM.md) or [spawn](../commands/spawn.md) scripts can, therefore [canSuspend](../commands/canSuspend.md) for these types of scripts will return [false](../commands/false.md).

## Syntax

```sqf
canSuspend
```

**Returns:** [Boolean](../topics/Boolean.md)

## Examples

### Example 1

```sqf
onEachFrame
{
    systemChat str canSuspend;            // false
    0 spawn { hint str canSuspend };    // true
    onEachFrame {};
};
```

### Example 2

Make sure the function code is always spawned even when called:

```sqf
private _sleepingCode =
{
    if (!canSuspend) exitWith { _this spawn _sleepingCode };
    sleep _this;
    hint ("slept " + str _this);
};

5 call _sleepingCode;
```

## See also

[sleep](../commands/sleep.md) · [uiSleep](../commands/uiSleep.md) · [waitUntil](../commands/waitUntil.md) · [call](../commands/call.md) · [spawn](../commands/spawn.md) · [execVM](../commands/execVM.md) · [isRemoteExecuted](../commands/isRemoteExecuted.md) · [isRemoteExecutedJIP](../commands/isRemoteExecutedJIP.md) · [remoteExecutedOwner](../commands/remoteExecutedOwner.md) · [isUIContext](../commands/isUIContext.md) · [isGamePaused](../commands/isGamePaused.md) · [isGameFocused](../commands/isGameFocused.md)

<sub>Source: [BI Community Wiki — canSuspend](https://community.bistudio.com/wiki/canSuspend) (revision 353403).</sub>
