# RefreshSchedule

> The timer behind a list that refreshes itself: it runs a reload every interval, one at a time, waits while paused, and on resume reloads at once when an interval has passed.

```ts
import { RefreshSchedule } from "@sdxc/ui/app";
```

Reloads on an interval measured from the last finished reload, so a slow reload never
stacks a second one behind it, and a resume after a long pause catches up with one reload.

## Signature

```ts
new RefreshSchedule(init: RefreshSchedule.Init)
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `init` | `RefreshSchedule.Init` | The interval and the reload to run. |

## Properties

| Property | Type | Description |
| --- | --- | --- |
| `every` | `readonly number` | Milliseconds between reloads. |
| `refreshedAt` | `Date` | When the last reload finished, or the initial content was fetched. |
| `paused` | `boolean` | Whether the schedule is waiting to be resumed. |

## Methods

| Method | Description |
| --- | --- |
| `start(): void` | Starts counting toward the next reload from the last refresh. |
| `pause(): void` | Holds the next reload until resume; a reload already running finishes. |
| `resume(): void` | Continues the schedule, reloading at once when a full interval passed while paused. |
| `stop(): void` | Ends the schedule for good. |

## Examples

```tsx
let schedule = new RefreshSchedule({ every: 30_000, reload: () => frame.reload() }); schedule.start();
```

## Used with it

The events, constants and types its module publishes, each imported from `@sdxc/ui/app` too.

### RefreshSchedule.Init

Construction options.

#### Members

| Member | Type | Description |
| --- | --- | --- |
| `every` | `number` | Milliseconds from the end of one reload to the start of the next; 0 or less never reloads. |
| `reload` | `() => Promise<unknown>` | Reloads what the schedule keeps current; a rejection leaves the schedule running. |
| `refreshedAt?` | `Date` | When the content on screen was last fetched. Defaults to construction time. |

### RefreshSchedule.Events

Events dispatched by RefreshSchedule.

#### Members

| Member | Type | Description |
| --- | --- | --- |
| `refresh` | `Event` | A reload finished; read `refreshedAt` for when. |
