# wait – vänta på värde

> Väntar tills en kanal når ett förväntat värde, eller tills timeout — för synkronisering i skript.

_Källa: E-Sharp (esharp.se) · Accordion Shell (CLI)_


## Description

The `wait` command monitors a channel until it reaches a specific value or until a timeout occurs. This is useful for synchronization and waiting for hardware state changes.

## Syntax

```bash
wait --channel <channel_name> --value <expected_value> [options]
```

## Required Options

| Option | Short | Description |
| --- | --- | --- |
| `--channel` | `-c` | The name or alias of the channel to monitor |
| `--value` | `-v` | The expected value to wait for |

## Optional Options

| Option | Short | Description | Default |
| --- | --- | --- | --- |
| `--timeout` | `-t` | Maximum time to wait in milliseconds | `1000` |

## Examples

```bash
wait --channel "READY_FLAG" --value "1"
wait --channel "STATUS" --value "IDLE" --timeout 5000
wait -c "VOUT" -v "3.3" -t 10000
wait -c "DEVICE_STATE" -v "INITIALIZED" -t 30000
```

## Output Format

Success: `READY_FLAG reached [1] after 234.56 ms` (green). Timeout: `STATUS didn't reach [IDLE] within the timeout` (red).

## Behavior

1. Starts a timer
2. Continuously reads the channel value (every 10 ms)
3. Compares value to expected value (exact match)
4. Returns immediately when match found
5. Throws timeout error if time limit exceeded

## Value Matching

The command performs exact string matching: `"1"` matches `"1"` but not `"1.0"` or `"true"`; `"3.3"` matches `"3.3"` but not `"3.30"`. Case-sensitive for strings.

## Use Cases

```bash
# Trigger operation and wait for completion
set -c "START_CONVERSION" -v "1"
wait -c "CONVERSION_DONE" -v "1" -t 1000
get -c "CONVERSION_RESULT"
```

## Notes

- Requires an active connection (use `init` first)
- Blocking operation (no other commands execute during wait)
- Use appropriate timeouts to avoid hanging

## Error Handling

- **Timeout**: Channel didn't reach expected value — increase timeout, verify expected value, check hardware
- **Channel not found**: Verify channel name with `list`
- **Not connected**: Run `init` command first
