AssetChannel

View source

Collects deferred reference-count operations for a typed asset pool in queue order.

Examples

import { AssetChannel, AssetChannelMessageType } from '@wimaengine/asset'

// An asset ID normally comes from a Handle<T>.id() call.
const assetId = 17
const channel = new AssetChannel()

channel.acquire(assetId)
const acquired = channel.flush()
channel.release(assetId)
const released = channel.flush()

console.log(acquired[0].type === AssetChannelMessageType.Acquire) // true
console.log(released[0].type === AssetChannelMessageType.Release) // true

Constructor


constructor<T>()

Type Parameters

T

Methods


acquire(assetId: AssetId): void

View source

Queue a reference acquisition for an asset ID.

Appends a new AssetChannelMessage with the AssetChannelMessageType.Acquire label. Messages remain in call order until AssetChannel#flush returns them; this method does not apply the operation or change a reference count.

Parameters

NameDescriptionDefault
assetId

Packed asset identity to acquire.

—

Returns

Always returns undefined.

release(assetId: AssetId): void

View source

Queue a reference release for an asset ID.

Appends a new AssetChannelMessage with the AssetChannelMessageType.Release label. Messages remain in call order until AssetChannel#flush returns them; this method does not apply the operation or change a reference count.

Parameters

NameDescriptionDefault
assetId

Packed asset identity to release.

—

Returns

Always returns undefined.

flush(): readonly AssetChannelMessage<T>[]

View source

Return the pending message batch.

Returns the current queue array in append order. If the queue is non-empty, this channel replaces it with a new empty array, so later messages do not appear in the returned batch. If the queue is empty, the same empty array remains the channel’s queue and is returned. This method does not interpret the operation labels.

Returns

The pending message array.