Releases one reference held by a handle immediately.
For a valid handle, this method releases one reference synchronously. If
other references remain, the asset stays in the pool and no event is
queued. When the count reaches zero, the asset is cleared, its index is
recycled, and an AssetDropped event is queued immediately. A
stale handle is ignored.
Unlike Handle#drop, this method does not mark the handle as
dropped or defer the release. Release each reference exactly once; calling
this method again on the same handle releases another reference while its
slot identity still matches.
Examples
import { AssetDropped, Assets } from '@wimaengine/asset'
class Texture {
constructor(name) {
this.name = name
}
}
const textures = new Assets(Texture)
const owner = textures.add(new Texture('player'))
const assetId = owner.id()
textures.flushEvents() // Clear the AssetAdded event.
const retained = textures.upgrade(assetId)
textures.drop(owner)
console.log(textures.getByAssetId(assetId).name) // 'player'
console.log(textures.flushEvents().length) // 0: one reference remains
textures.drop(retained)
const [event] = textures.flushEvents()
console.log(event instanceof AssetDropped) // true
console.log(event.id === assetId) // true
console.log(textures.getByAssetId(assetId)) // undefined