js/runtime

js/runtime.ts

fino:runtime — control whether asynchronous resources keep a realm alive.

Runtime handles are referenced by default. unref() allows an otherwise idle realm to exit while the resource remains able to deliver events whenever other referenced work is active. ref() restores normal liveness and hasRef() reports the current state.

Numeric web timer IDs are supported without changing the web-compatible timer return type. Fino resource objects may implement the same three methods and are delegated to directly.

import { unref } from 'fino:runtime';

const maintenance = setInterval(() => refreshCache(), 30_000);
unref(maintenance);

Interfaces

interface RuntimeRefable {

A Fino resource whose contribution to realm liveness can be controlled.

Methods

ref(): this

Make this resource keep its realm alive and return the resource.

unref(): this

Stop this resource from keeping its realm alive and return the resource.

hasRef(): boolean

Whether this resource currently keeps its realm alive.

Functions

function ref<T extends number | RuntimeRefable>(handle: T): T

Make handle keep the current realm alive.

handle may be a live numeric ID returned by a web timer function or a Fino resource implementing {@link RuntimeRefable}. Unknown timer IDs and objects without the refable contract throw.

function unref<T extends number | RuntimeRefable>(handle: T): T

Stop handle from keeping the current realm alive.

The resource is not canceled. It may continue delivering events while other referenced work keeps the realm running. Realm disposal eventually cancels any remaining unreferenced resources.

function hasRef(handle: number | RuntimeRefable): boolean

Return whether handle currently contributes to realm liveness.