Skip to content

identity()

identity(value) opts a value into reference identity across the connection. By default every send produces a fresh copy; wrapping with identity() makes the same object revive as the same reference on every send, and a round trip back to the sender resolves to the original object.

const identity: <T>(value: T) => T

identity() is idempotent, and primitives pass through unchanged.

Without identity(), every send produces an independent copy — including the return trip: a revived value passed back bare arrives as a fresh copy, so the returning side must re-wrap it.

Wrapping changes both directions:

  • Same reference on every send: sending the same wrapped value twice revives as the same object on the peer.
  • Round trip to the original: when the peer wraps the revived object in identity() and sends it back, you receive your original reference (===).

identity() also dedupes repeat sends on the wire: the first send ships the payload plus an id, later sends of the same reference ship only the id, and the peer reuses its cached revived value — see performance.

Repeat sends revive as one object:

import {
const identity: <T>(value: T) => T

Wrap a value so osra preserves reference identity across the RPC boundary. Idempotent; primitives pass through unchanged. Lies at the type level - runtime value is an IdentityWrapper typed as T.

identity
} from 'osra'
const
const config: {
mode: string;
}
config
= {
mode: string
mode
: 'fast' }
await
const remote: {
register: (config: {
mode: string;
}) => Promise<void>;
}
remote
.
register: (config: {
mode: string;
}) => Promise<void>
register
(
identity<{
mode: string;
}>(value: {
mode: string;
}): {
mode: string;
}

Wrap a value so osra preserves reference identity across the RPC boundary. Idempotent; primitives pass through unchanged. Lies at the type level - runtime value is an IdentityWrapper typed as T.

identity
(
const config: {
mode: string;
}
config
))
await
const remote: {
register: (config: {
mode: string;
}) => Promise<void>;
}
remote
.
register: (config: {
mode: string;
}) => Promise<void>
register
(
identity<{
mode: string;
}>(value: {
mode: string;
}): {
mode: string;
}

Wrap a value so osra preserves reference identity across the RPC boundary. Idempotent; primitives pass through unchanged. Lies at the type level - runtime value is an IdentityWrapper typed as T.

identity
(
const config: {
mode: string;
}
config
)) // peer sees the same object twice

For a round-trip walkthrough — handing a reference to the peer and receiving the original back — see identity and transfer.

Per-connection identity caches are GC-aware: when the sender of an identity()-tracked value garbage-collects the original, the peer is notified via an identity-dispose envelope and evicts its cached revival. Receivers never send identity-dispose; their cache holds strong references.