---
title: "Delay"
source: standard-library
version: genesis-0-1-0
id: standard-library/4-plugins/delay
canonical: /docs/standard-library/4-plugins/delay
---

# Delay

The delay plugin schedules timeout and interval timers and emits vibration callbacks when timers tick. Each vibration key maps to a timer operation function. Invalid timer payloads are rejected and reported through logs.

## Functions

---

## sec

Schedules one-shot timeout using plain sec numeric input.

```
2  delay.sec ? // vibrates 2 after 2 seconds
```

Collector input is invalid, no vibration will happen.

```
(1,2)  delay.sec ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_ARGUMENT_TYPE
- **Message:** delay.sec expects a single numeric value.

Zero or invalid delay values are rejected, no vibration will happen.

```
0  delay.sec ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_DELAY_VALUE
- **Message:** Delay must be a positive number.

---

## ms

Schedules one-shot timeout using plain ms numeric input.

```
2000  delay.ms? // vibrates 2000 after 2000 milliseconds
```

Collector input is invalid, no vibration will happen.

```
(1,2)  delay.ms ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_ARGUMENT_TYPE
- **Message:** delay.ms expects a single numeric value.

Zero or invalid delay values are rejected, no vibration will happen.

```
0  delay.sec ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_DELAY_VALUE
- **Message:** Delay must be a positive number.

---

## setTimeout

Schedules one-time callback using array payload: index 0 is timer id (string), index 1 is delay in milliseconds (number).

```
("t1",500)  delay.setTimeout ? // schedules one-shot tick
```

Missing id at index 0 causes rejection.

```
(500)  delay.setTimeout ? // no vibration
```

- **Type:** ERROR
- **Code:** MISSING_REQUIRED_FIELD
- **Message:** setTimeout payload must contain id at index 0.

Missing delay milliseconds at index 1 causes rejection.

```
("t1")  delay.setTimeout ? // no vibration
```

- **Type:** ERROR
- **Code:** MISSING_DELAY_VALUE
- **Message:** setTimeout payload must contain delay ms at index 1.

Non-array payload is invalid.

```
500  delay.setTimeout ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_ARGUMENT_TYPE
- **Message:** setTimeout expects an array payload.

---

## setInterval

Receives an array with timer id at index 0 and interval milliseconds at index 1, then schedules repeating vibration. onTick can be used to receive the vibrations back.

```
("i1",1000)  delay.setInterval ? // repeats onTick
```

Missing id at index 0 causes rejection.

```
(1000)  delay.setInterval ? // no vibration
```

- **Type:** ERROR
- **Code:** MISSING_REQUIRED_FIELD
- **Message:** setInterval payload must contain id at index 0.

Missing delay milliseconds at index 1 causes rejection.

```
("i1")  delay.setInterval ? // no vibration
```

- **Type:** ERROR
- **Code:** MISSING_DELAY_VALUE
- **Message:** setInterval payload must contain delay ms at index 1.

Non-array payload is invalid.

```
1000  delay.setInterval ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_ARGUMENT_TYPE
- **Message:** setInterval expects an array payload.

---

## onTick

This function is used to receive the vibrations back from active intervals and timeouts.

```
delay.onTick? // vibrates with the id of the timer
```

---

## ms

Schedules one-shot timeout using plain ms numeric input.

```
2000  delay.ms? // vibrates 2000 after 2000 milliseconds
```

Collector input is invalid, no vibration will happen.

```
(1,2)  delay.ms ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_ARGUMENT_TYPE
- **Message:** delay.ms expects a single numeric value.

Zero or invalid delay values are rejected, no vibration will happen.

```
0  delay.sec ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_DELAY_VALUE
- **Message:** Delay must be a positive number.

---

## cancel

Cancels interval/timeout by timer id string.

```
"i1"  delay.cancel ? // clears timer i1
```

Non-string id values are invalid.

```
123  delay.cancel ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_ARGUMENT_TYPE
- **Message:** cancel expects a string timer id.

If Id is not found, no vibration will happen.

```
"invalid_id" delay.cancel ? // no vibration
```

- **Type:** ERROR
- **Code:** INVALID_TIMER_ID
- **Message:** cancel expects a valid timer id.
