Skip to content

Resource

Limits concurrent entry into application-defined scopes.

Constructor

Resource count

Creates a resource with count concurrent reservations.

Raises ValueError if count is zero.

Parameters

NameTypeDescription
count Int maximum concurrent admissions

Methods

with[R] block -> R

Runs block while holding one reservation.

Entering the same resource again in the same strand is reentrant. Scoped child strands inherit the reservation and share it with their parent. Background strands created with spawn or stream do not inherit reservations.

Acquiring multiple resources in inconsistent orders can deadlock. Programs must use a consistent acquisition order.

Resources limit admission only and must not be used to protect critical-section invariants.

Parameters

NameTypeDescription
block (() -> R) scoped work to execute

Example

network.with do
  fetch_data()