# Thread

The class Thread has the following methods:

### ***getData***

this method returns the Thread's attached DATA

| Returns |          |
| ------- | -------- |
| DATA    | the date |

### ***start***

this method starts the Thread

| Returns |   |
| ------- | - |
| void    | - |

### ***stop***

this method stops the Thread

| Input          |                                                                                                                                                                            |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| eventsConsumer | <p><strong>Type:</strong>  <code>(events) => void </code><em><code>required</code></em></p><p>a function that will receive all the events until the thread was stopped</p> |

| Returns |   |
| ------- | - |
| void    |   |

### ***next***

this method will call the callback passed as param when the thread's state changes

| Input |                                                                                                                                                                                   |
| ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cb    | <p><strong>Type:</strong>  <code>(onNext: Context\<ThreadFlow\<DATA>, 'nextData', { nextData: REDUCERS }>) </code><em><code>required</code></em></p><p>the callback to invoke</p> |

| Returns |   |
| ------- | - |
| void    |   |

�

### ***addReaction***

this method allows to add a reaction on the thread

| Input |                                                                                                                                      |
| ----- | ------------------------------------------------------------------------------------------------------------------------------------ |
| def   | <p><strong>Type:</strong>  <code>DataReactionDef\<DATA> </code><em><code>required</code></em></p><p>the data reaction definition</p> |

| Returns          |                                 |
| ---------------- | ------------------------------- |
| DataReactionLock | TBC: Alberto qué mierda es esto |

### ***chain***

this method allows to chain a callback to the next data update

| Input      |                                                                                                                                                    |
| ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| mutatorsCb | <p><strong>Type:</strong>  <code>IConsumer\<REDUCERS & DefaultStepFn\<DATA>> </code><em><code>required</code></em></p><p>the callback to chain</p> |
| name       | <p><strong>Type:</strong>  <code>string </code><em><code>optional</code></em></p><p>the name passed will be eaten by the framework and ignored</p> |

| Returns     |                                   |
| ----------- | --------------------------------- |
| Asap\<DATA> | The up to date DATA of the Thread |

### ***monitor\<T>***

this method allows to perform async operations within a thread in a controlled way

| Input        |                                                                                                                                                                                      |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| toMonitor    | <p><strong>Type:</strong>  <code>Asap\<T> </code><em><code>required</code></em></p><p>the Asap we want to monitor</p>                                                                |
| thenCallback | <p><strong>Type:</strong>  <code>IBiConsumer\<T, REDUCERS & DefaultStepFn\<T>> </code><em><code>required</code></em></p><p>callback function to invoke when the Asap is resolved</p> |
| payload      | <p><strong>Type:</strong>  <code>any </code><em><code>optional</code></em></p><p>payload used for logging</p>                                                                        |
|              |                                                                                                                                                                                      |

| Returns     |                                   |
| ----------- | --------------------------------- |
| Asap\<DATA> | The up to date DATA of the Thread |

### ***isRunning***

true of the underlying flow is running

| Returns |   |
| ------- | - |
| Boolean | - |

### ***reducers***

returns the underlying flow reducers

| Returns                         |   |
| ------------------------------- | - |
| REDUCERS & DefaultStepFn\<DATA> |   |

### ***getEvents***

returns the underlying flow events

| Returns                               |   |
| ------------------------------------- | - |
| FlowEventsTracker<{ nextData: DATA }> |   |

### ***getName***

returns the underlying flow name

| Returns |   |
| ------- | - |
| string  |   |

### ***changeLoggingNature***

gives access to changing the underlying flow logging nature

| Input  |                                                                                                                         |
| ------ | ----------------------------------------------------------------------------------------------------------------------- |
| nature | <p><strong>Type:</strong>  <code>FlowEventNature </code><em><code>required</code></em></p><p>the new logging nature</p> |

| Returns |   |
| ------- | - |
| void    | - |

### ***log***

logs a message

| Input |                                                                                                            |
| ----- | ---------------------------------------------------------------------------------------------------------- |
| msg   | <p><strong>Type:</strong>  <code>string </code><em><code>required</code></em></p><p>the message to log</p> |

| Returns |   |
| ------- | - |
| void    |   |

### ***once***

adds a reaction once to the underlying flow

| Input    |                                                                                                                                 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| reaction | <p><strong>Type:</strong>  <code>IConsumer\<DATA> </code><em><code>required</code></em></p><p>the reaction to add</p>           |
| name     | <p><strong>Type:</strong>  <code>string </code><em><code>optional</code></em></p><p>reaction name used for logging purposes</p> |

| Returns |   |
| ------- | - |
| this    |   |


---

# 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.conanjs.io/api/conan-state-classes/thread.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.
