ExchangeTable

class ExchangeTable<ID0 : Any, ID1 : Any, VS : Any, VR : Any> constructor(clock: <Error class: unknown class>)

A concurrency utility for coordinating request/response style exchanges between coroutines.

The table maintains two sides of communication:

  • Send table: holds values that represent requests (VS).

  • Receive table: holds values that represent responses (VR).

A request is initiated by calling waitFor, which stores the request data and suspends until a corresponding response is provided by notify. After completion (either by success or timeout), both request and response entries are cleaned up automatically.

Key Properties

  • Identifiers are composed of two parts: ID0 (outer) and ID1 (inner).

  • Each (id0, id1) pair may have at most one active waiter at a time.

  • Requests and responses are timestamped internally to support cleanup.

This abstraction is useful for modeling one-off message exchanges, such as RPC-style request/response patterns or matching commands with replies.

Parameters

ID0

type of the outer identifier

ID1

type of the inner identifier

VS

type of values stored in the send table (requests)

VR

type of values stored in the receive table (responses)

Constructors

Link copied to clipboard
constructor()
constructor(clock: <Error class: unknown class>)

optionally provide a Clock (defaults to Clock.System) for timestamping

Functions

Link copied to clipboard
suspend fun dropAllBefore(timestamp: <Error class: unknown class>)

Drops all entries (both send and receive) whose timestamps are older than timestamp.

Link copied to clipboard
suspend fun notify(id0: ID0, id1: ID1, data: VR)

Notifies the exchange with a response for the given id0 and id1.

Link copied to clipboard
fun subscribeSend(id: ID0): <Error class: unknown class><StateEvent<ID1, VS>>

Subscribes to request events in the send table for a given id.

Link copied to clipboard
suspend fun waitFor(id0: ID0, id1: ID1, data: VS, timeout: <Error class: unknown class>? = null): VR

Waits for a response associated with the given id0 and id1.