# CoroutineInterruptToken

Class in [Effects](/2.2/api/csharp/yarn.unity/yarn.unity.effects.md)

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()](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.start.md) to mark that the coroutine is running. During the coroutine's execution, periodically check the [WasInterrupted](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.wasinterrupted.md) 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()](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.complete.md) method to mark that the coroutine is no longer running. To make a coroutine stop, call the [Interrupt()](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.interrupt.md) method.

You can also use the [CanInterrupt](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.caninterrupt.md) 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()](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.complete.md)   |             |
| [Interrupt()](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.interrupt.md) |             |
| [Start()](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.start.md)         |             |

## Properties

| Name                                                                                                                                                                    | Description |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| [CanInterrupt](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.caninterrupt.md)     |             |
| [WasInterrupted](/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken/yarn.unity.effects.coroutineinterrupttoken.wasinterrupted.md) |             |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yarnspinner.dev/2.2/api/csharp/yarn.unity/yarn.unity.effects/yarn.unity.effects.coroutineinterrupttoken.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
