# groundedDebounce
Source: https://docs.maelstrom-ai.co/dev/reference/realtime/functions/groundeddebounce/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

> **groundedDebounce**<`A`\>(`fn`, `ms`): (…`args`) => `void` &amp; `object`

Defined in: [packages/realtime/src/lib/realtime-session/grounding-debounce.ts:21](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/grounding-debounce.ts#L21)

Wraps `fn` so that only the most recent call within a trailing `ms` window actually fires — intermediate calls are discarded, not queued. Used to collapse rapid render-settle events into a single grounding push carrying the latest structural snapshot: the model should never see a burst of stale grounding text for a UI state that has already moved on.

The returned function carries a `cancel()` so a caller tearing down the session this debounce belongs to can drop a pending trailing call — otherwise it fires on its own timer after teardown and can land as a new session’s first grounding push.

## Type Parameters

### A

`A` _extends_ `unknown`\[\]

## Parameters

### fn

(…`args`) => `void`

### ms

`number`

## Returns

(…`args`) => `void` &amp; `object`

## Example

```ts
const push = groundedDebounce((snapshot: UIStructuralSnapshot) => {
  adapter.injectGrounding(summarize(snapshot));
}, 1000);
push.cancel(); // e.g. on session disconnect
```
