# TimeModule

`clearInterval`

`clearInterval(timer: Subscription): void`

Cancels a callback set by `setInterval`. This function is provided as a to match the traditional JS `clearInterval` API.

**Note**: This is equivalent to `Subscription.unsubscribe`.

`clearTimeout`

`clearTimeout(timer: Subscription): void`

Cancels a callback set by `setTimeout`. This has no effect if the timeout has already been triggered. This function is provided as a to match the traditional JS `clearTimeout` API.

**Note**: This is equivalent to `Subscription.unsubscribe`.

`setInterval`

`setInterval(callback: Function, delay: Number): Subscription`

Returns a `Subscription` object. The function specified by `callback` is called at intervals specified by `delay` in milliseconds. The `setInterval` will continue calling the `callback` until `TimeModule.clearInterval` is called. The `callback` is a function that has one argument, the elapsed time since the timer started. An exception is thrown when the `delay` is zero or less.

**Note**: An interval can be canceled either via `Subscription.unsubscribe` or `TimeModule.clearInterval`.

`setIntervalWithSnapshot`

`setIntervalWithSnapshot(snapshot: { [name: string]: Signal}, callback: Function, delay: Number): Subscription` Returns a `Subscription` object. The function specified by `callback` is called at intervals specified by `delay` in milliseconds using `Snapshot` of signals. `Snapshot` is a dictionary of String/Bool/Scalar signals, which will be passed as JSON to the callback function using lastValue from requested signals.

The `setIntervalWithSnapshot` will continue calling the `callback` until `TimeModule.clearInterval` is called. The `callback` is a function that has two arguments, the elapsed time since the timer started, and the snapshot JSON An exception is thrown when the `delay` is zero or less.

**Note**: An interval can be canceled either via `Subscription.unsubscribe` or `TimeModule.clearInterval`.

`setTimeout`

`setTimeout(callback: Function, delay: Number): Subscription`

Returns a `Subscription` object. The function specified by `callback` is called after the specified `delay` in milliseconds. The `callback` is a function that has one argument, the elapsed time since the timer started.

**Note**: A timeout can be canceled either via `Subscription.unsubscribe` or `TimeModule.clearTimeout`.

**Note**: This is equivalent to `Time.ms.sub(Time.ms.pin()).trigger(delay).subscribe(callback)`.

`setTimeoutWithSnapshot`

`setTimeoutWithSnapshot(snapshot: { [name: string]: Signal}, callback: Function, delay: Number): Subscription`

Returns a `Subscription` object. The function specified by `callback` is called after the specified `delay` in milliseconds using `Snapshot` of signals. `Snapshot` is a dictionary of String/Bool/Scalar signals, which will be passed as JSON to the callback function using lastValue from requested signals.

The `callback` is a function that has two arguments, the elapsed time since the timer started and the snapshot JSON.

**Note**: A timeout can be canceled either via `Subscription.unsubscribe` or `TimeModule.clearTimeout`.

**Note**: This is equivalent to `Time.ms.sub(Time.ms.pin()).trigger(delay).subscribeWithSnapshot(snapshot, callback)`.


---

# 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://sparkar-community.gitbook.io/docs/timemodule.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.
