# Delays & Queues

In many games, producing, consuming, and trading resources takes time. The time it requires to complete an action might be crucial for the game balance - think about all the games out there with a time-based economy.&#x20;

#### Same Node, 2 actions:

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-MMH4osZGbHtlux9Rj-s%2F-MMH6w6lzGWExDD86HMo%2FScreen%20Recording%202020-11-16%20at%2007.34%20PM.gif?alt=media&#x26;token=40bdba5c-7575-4d85-ad2c-5dfb7cb06858" alt=""></div>

### Delays

{% hint style="success" %}
In a Machinations diagram, use a Delay Node to delay the flow of Resources as they get distributed in your diagram.
{% endhint %}

A delay is represented by a small circle with an hourglass inside.

{% hint style="warning" %}
The [Label](https://machinations.gitbook.io/docs/labels) on the delay’s output indicates how many time steps a Resource is delayed.&#x20;

Note that this is different from most Labels on Resource Connections, which ordinarily represent a flow rate.&#x20;

**This time is dynamic**, it can be changed by other elements in the diagram via Label Modifiers.
{% endhint %}

:wrench: In the example below, notice the count of running steps in the bottom right corner, and the flow of the Soldiers Resource. It is delayed by 5 steps.

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-MMH1CDPZIJsbsiz98uk%2F-MMH3Ddnx4z_2XipbLZn%2FScreen%20Recording%202020-11-16%20at%2007.16%20PM.gif?alt=media&#x26;token=cbd87263-2033-49e4-8350-1c95042be1d5" alt=""></div>

Here's the step by step rundown:\
\&#xNAN;*Step 1:* Three Gold are converted into a Soldier & sent to Delay\
\&#xNAN;*Steps 2 - 6:* the Soldier is delayed \
\&#xNAN;*Step 7:* Resource gets pushed to the Soldiers Pool.

A Delay can process multiple Resources simultaneously. This means that all incoming Resources are delayed for the specified number of time steps regardless of the number of Resources currently being delayed.

{% hint style="info" %}
Other elements in the diagram can change the delay setting through label modifiers.&#x20;

Or you can specify a random delay time using dice notation.
{% endhint %}

### Queues

{% hint style="success" %}
Delays can be turned into Queues. A Queue has 2 hourglass symbols instead of one.&#x20;

Queues process only one Resource at a time.
{% endhint %}

:wrench: In the example below, notice the counter of running steps in the bottom right corner, and the flow of the Soldiers Resource. In this case, orders from Build are queued and processed 1 at a time, every 5 steps.

<div align="left"><img src="https://2667914601-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGZcALyOGDKb9q0wdJ5%2F-MMH1CDPZIJsbsiz98uk%2F-MMH4aoaUt1ajrO1wudp%2FScreen%20Recording%202020-11-16%20at%2007.24%20PM.gif?alt=media&#x26;token=073e2044-42bb-47a7-bb33-9d0b1e9c3bd8" alt=""></div>

Step by step rundown:\
\&#xNAN;*Step 1:* Three Gold are converted into a Soldier & sent to Queue\
\&#xNAN;*Step 2:*  Initial Soldier is being Queued for 1 step. Another three Gold are converted into a Soldier & sent to Queue\
\&#xNAN;*Step 3-5:* the first Soldier is delayed & the second Soldier waits in queue\
\&#xNAN;*Step 6:* the first Soldier gets pushed to the Soldiers Pool & the second Soldier starts being delayed\
Step 6-10: the second Soldier is delayed\
Step 11: the second Soldier gets pushed to the Soldiers Pool

{% hint style="success" %}
Delays and Queues can use State Connections that communicate the number of Resources they are currently processing (including the number of Resources waiting in a Queue to be processed).&#x20;
{% endhint %}
