# CoroutineInterruptToken

Class in [Effects](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects)

Inherits from `System.Object`

## Summary

An object that can be used to signal to a coroutine that it should terminate early.

```csharp
public class CoroutineInterruptToken
```

## Remarks

While coroutines can be stopped by calling `MonoBehaviour.StopCoroutine` or `MonoBehaviour.StopAllCoroutines`, this has the side effect of also stopping any coroutine that was waiting for the now-stopped coroutine to finish.

Instances of this class may be passed as a parameter to a coroutine that they can periodically poll to see if they should terminate earlier than planned.

To use this class, create an instance of it, and pass it as a parameter to your coroutine. In the coroutine, call [Start()](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.start) to mark that the coroutine is running. During the coroutine's execution, periodically check the [WasInterrupted](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.wasinterrupted) property to determine if the coroutine should exit. If it is `true`, the coroutine should exit (via the `yield break` statement.) At the normal exit of your coroutine, call the [Complete()](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.complete) method to mark that the coroutine is no longer running. To make a coroutine stop, call the [Interrupt()](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.interrupt) method.

You can also use the [CanInterrupt](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.caninterrupt) property to determine if the token is in a state in which it can stop (that is, a coroutine that's using it is currently running.)

## Methods

| Name                                                                                                                                                                                     | Description |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| [Complete()](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.complete)   |             |
| [Interrupt()](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.interrupt) |             |
| [Start()](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.start)         |             |

## Properties

| Name                                                                                                                                                                                             | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- |
| [CanInterrupt](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.caninterrupt)     |             |
| [WasInterrupted](https://docs.yarnspinner.dev/2.1/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.wasinterrupted) |             |
