# @askrjs/askr/resources

> Published API exports for @askrjs/askr/resources.

Source: [https://askrjs.com/docs/reference/api/askr/resources](https://askrjs.com/docs/reference/api/askr/resources)

Status: stable. Packages: @askrjs/askr/resources.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Exports

This entrypoint publishes 20 exports from the declarations shipped by @askrjs/askr.

### `ActivityPredicate`

```ts
ActivityPredicate: () => boolean
```

A gating condition for lifecycle primitives like {@link timer}; `true` means active.

### `capture`

```ts
capture: <T>(fn: () => T) => () => T
```

Capture the result of a synchronous expression at call time and return a
thunk that returns the captured value later. This is a low-level helper for
cases where async continuations need to observe a snapshot of values at the
moment scheduling occurred.

Usage (public API):
const snapshot = capture(() => someState());
Promise.resolve().then(() => { use(snapshot()); });

### `documentVisible`

```ts
documentVisible: () => ActivityPredicate
```

{@link ActivityPredicate} that is true while the document is visible.

### `getSignal`

```ts
getSignal: () => AbortSignal
```

Get the abort signal for the current component.

The signal is guaranteed to be aborted when:
- Component unmounts
- Navigation occurs (different route)
- Parent is destroyed

### `ListenerTarget`

```ts
ListenerTarget: EventTarget | (() => EventTarget | null | undefined)
```

An event target, or a function resolving one, accepted by {@link on}.

### `on`

```ts
on: (target: ListenerTarget, event: string, handler: EventListener, options?: ListenerOptions) => void
```

Attach an owned event listener to `target` for the current component's lifetime.

### `onRouteChange`

```ts
onRouteChange: (fn: (current: RouteSnapshot, previous: RouteSnapshot | null) => RouteChangeCleanup, options?: RouteChangeOptions) => void
```

Register a callback to run whenever the active route changes, with optional cleanup.

### `resource`

```ts
resource: <T, const TDeps extends readonly unknown[]>(fn: (opts: { signal: AbortSignal; }) => PromiseLike<T> | T, deps: TDeps) => ResourceResult<T>
```

Creates a render-scoped async resource with cancellation and refresh; SSR has special data rules.

### `ResourceResult`

```ts
ResourceResult: any
```

Reactive result of a {@link resource}: current value, loading state, and controls.

- `value`: value: T | null;

- `pending`: pending: boolean;

- `error`: error: Error | null;

- `refresh`: refresh(): void;

### `routeActive`

```ts
routeActive: (pathOrPaths: string | readonly string[]) => ActivityPredicate
```

{@link ActivityPredicate} that is true while the current route matches `pathOrPaths`.

### `RouteChangeCleanup`

```ts
RouteChangeCleanup: void | (() => void)
```

Optional cleanup returned by an {@link onRouteChange} callback, run before the next change.

### `RouteChangeOptions`

```ts
RouteChangeOptions: any
```

Options for {@link onRouteChange}.

- `immediate`: immediate?: boolean;

### `stream`

```ts
stream: <T>(source: StreamSource<T>, options?: StreamOptions<T>) => StreamResult<T>
```

Subscribe to a streaming data source for the current component's lifetime, with auto reconnect/cleanup.

### `StreamOptions`

```ts
StreamOptions: any
```

Options for {@link stream}.

- `deps`: deps?: readonly unknown[];

- `initialValue`: initialValue?: T;

### `StreamResult`

```ts
StreamResult: any
```

Reactive result of a {@link stream}: current value, connection status, and controls.

- `value`: value: T | null;

- `status`: status: StreamStatus;

- `pending`: pending: boolean;

- `stale`: stale: boolean;

- `error`: error: Error | null;

- `restart`: restart(): void;

- `close`: close(): void;

### `StreamStatus`

```ts
StreamStatus: 'connecting' | 'connected' | 'reconnecting' | 'closed' | 'error'
```

Connection status of a {@link stream}.

### `task`

```ts
task: (fn: () => void | (() => void) | PromiseLike<void | (() => void)>) => void
```

Runs an owned task after commit.

### `timer`

```ts
timer: (intervalMs: number, fn: () => void, options?: TimerOptions) => void
```

Run `fn` on an owned interval for the current component's lifetime, optionally gated by `options.when`.

### `TimerOptions`

```ts
TimerOptions: any
```

Options for {@link timer}.

- `when`: when?: ActivityPredicate | readonly ActivityPredicate[];

### `windowFocused`

```ts
windowFocused: () => ActivityPredicate
```

{@link ActivityPredicate} that is true while the window has focus.

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/askr/foundations--icon/index.md) | [Next](https://askrjs.com/docs/reference/api/askr/data/index.md)
