# wrPoll

> Reloads a resource on an interval: one timer shared across the app, paused while the page is hidden, a loading resource skipped on its turn.

Source: https://ngwr.dev/reference/utils/wr-poll  
Kind: Util  
Added in v15.5  
Optional

## Installation

Import the class. This entry point has no stylesheet.

```typescript
import { wrPoll } from 'ngwr/platform';
```

## Usage

Takes `resource()`, `rxResource()` and `httpResource()` alike. Needs an injection context and stops with it. Lives in `ngwr/platform`, since it reads `WrPlatform.pageVisible`.

```angular-ts
import { httpResource } from '@angular/common/http';
import { wrPoll } from 'ngwr/platform';

@Component({
  template: `<wr-table [items]="rows()" [loading]="orders.isLoading()" />`,
})
export class Orders {
  readonly orders = httpResource<Order[]>(() => '/api/orders');
  readonly rows = wrResourceValue(this.orders, []);

  constructor() {
    wrPoll(this.orders, 15_000);
  }
}
```

## Rules

| When | What happens |
| --- | --- |
| Two resources, two intervals | One timer, aimed at the earliest due resource. |
| The tab is hidden | Polling pauses. On return, a resource overdue by its interval reloads once. |
| Still loading on its turn | Skipped, not queued: it waits a full interval again. |
| In the `error` state | Keeps polling. That is how it recovers. |
| On the server | Nothing is scheduled, so prerender never waits. |

## API

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `wrPoll(resource, intervalMs)` | Reloads `resource` every `intervalMs` while the page is visible, on the one shared timer. Needs an injection context and stops with it. Throws in dev mode on an interval that is not positive. | `<T>(resource: WritableResource<T>, intervalMs: number) => void` | `-` |

## See also

- [WrPlatform](https://ngwr.dev/reference/services/platform) — SSR-safe browser checks, user-preference and page-state signals, a return callback and haptics.
- [wrAction](https://ngwr.dev/reference/utils/wr-action) — One async write as signals: status, loading, value, error, a single-flight run().
