Skip to content

Class: WireStatus ​

Defined in: src/wirestate-core/activation/wire-status.ts:77

Read-only lifecycle status for one resolved service instance.

Remarks ​

Wirestate keeps one stable WireStatus object per resolved service instance and updates it as the container and provider lifecycle progress. Application code can hold a reference and read the current flags without mutating the instance or requiring a base class. The flags are readonly: Wirestate advances them internally, and application code only reads them.

Accessors ​

isInactive ​

Get Signature ​

ts
get isInactive(): boolean;

Defined in: src/wirestate-core/activation/wire-status.ts:184

Whether the instance should stop work because its lifecycle ended.

Remarks ​

Derived from isDeactivated and isDeprovisioned.

Returns ​

boolean

true once the instance was deactivated or deprovisioned.

Lifecycle ​

isStale() ​

ts
isStale(provisionId: Nullable<number>): boolean;

Defined in: src/wirestate-core/activation/wire-status.ts:222

Reports whether work started in a provision cycle should be discarded.

Parameters ​

ParameterTypeDescription
provisionIdNullable<number>Provision cycle the work belongs to, as passed to @OnProvision or snapshotted from WireStatus.provisionId.

Returns ​

boolean

Whether the work belongs to an ended or superseded lifecycle.

Remarks ​

The guard for anything that resumes after an await. It is stale when the instance ended its lifecycle (deactivated or deprovisioned) or when a newer provision cycle has superseded the one the work belongs to:

ts
public async onProvision(provisionId: ProvisionId): Promise<void> {
  const result = await loadResult();

  if (this.status.isStale(provisionId)) {
    return;
  }

  this.applyResult(result);
}

Both clauses matter. Deprovision restores provisionId to the value the hook received, and deactivation leaves it untouched, so an id comparison alone stays equal and lets a late result through after the lifecycle has ended.

Outside a provision hook, snapshot provisionId before the await and pass the snapshot back. A null snapshot means the instance had not been provisioned yet, and stays current until a cycle starts.


for() ​

ts
static for(instance: object): WireStatus;

Defined in: src/wirestate-core/activation/wire-status.ts:95

Returns the lifecycle status tracked for a resolved service instance.

Parameters ​

ParameterTypeDescription
instanceobjectResolved service instance to inspect.

Returns ​

WireStatus

The stable lifecycle status for the instance.

Remarks ​

Use this inside service methods when async work needs to check whether the service has been deactivated or deprovisioned. The instance must already be tracked, which it is from activation onward, so every lifecycle hook and any method reachable from one can call it. To start tracking from a constructor, where activation has not run yet, use WireStatus.track instead.

Throws ​

WirestateError If the object is not tracked by Wirestate.


track() ​

ts
static track(instance: object): WireStatus;

Defined in: src/wirestate-core/activation/wire-status.ts:124

Starts lifecycle tracking for an instance and returns its status.

Parameters ​

ParameterTypeDescription
instanceobjectService instance to track.

Returns ​

WireStatus

The stable lifecycle status for the instance.

Remarks ​

Use this in a service constructor to hold the status as a field, which is the only form that reaches async methods outside the lifecycle hooks:

ts
public constructor(private readonly status: WireStatus = WireStatus.track(this)) {}

Idempotent: an already-tracked instance keeps its existing status object, so a constructor call and the later activation share one stable status.

Properties ​

isDeactivated ​

ts
readonly isDeactivated: boolean = false;

Defined in: src/wirestate-core/activation/wire-status.ts:138

Whether the instance was deactivated and removed from its container.


isDeprovisioned ​

ts
readonly isDeprovisioned: Nullable<boolean> = null;

Defined in: src/wirestate-core/activation/wire-status.ts:148

Whether the instance has been removed from provider ownership.

Remarks ​

null means the instance has not reached provider lifecycle yet. false means the instance is currently owned by a provider. true means the provider deprovisioned it.


provisionId ​

ts
readonly provisionId: Nullable<number> = null;

Defined in: src/wirestate-core/activation/wire-status.ts:162

Current provider provision cycle ID for the instance.

Remarks ​

Every instance a container owns is stamped for the cycle, not only the ones declaring @OnProvision or @OnDeprovision, so WireStatus.isStale can report a superseded cycle for any service.

null means the instance has not entered a tracked provider provision cycle: it is not owned by a provisioned container, or it was resolved after the current cycle had already wired its instances, in which case the next cycle stamps it.