Skip to content

components/shared-component-pool-component

A pool that shares one loaded component per caller-defined key among several consumers, and unloads it when the last consumer releases it.

Class Description
SharedComponentPoolComponent Shares one loaded component per caller-defined key among several consumers. The first acquire of a key creates the component through the factory and loads it; every further acquire of the same key, concurrent or later, receives the same instance; the release of the last acquisition unloads it, and the next acquire creates a fresh one. A ComponentEx is loaded through ComponentEx.loadWithPromises, so an acquire resolves only once its onloadAsync and children have settled, and a failed load rejects every waiting acquire, unloads the component and leaves the key free for a fresh attempt. The pool is itself a component, and its parent is the owner of every shared instance: add it with addChild to the plugin (or any longer-lived component). Unloading the owner unloads every shared component still held, rejects every acquire still waiting with a SilentError, and refuses later acquires. Keys are compared the way a Map compares them, so two equal-looking object keys are two resources. The instances live on the pool object only, never in the shared-state bag, so two plugins — or two pools of one plugin — never share anything. Reach for it only when SEVERAL independent consumers want the same expensive component and none of them owns it. A component with a single owner is that owner’s child: addChild is simpler and already unloads it with its owner.
Interface Description
SharedComponentAcquisition One consumer’s hold on a shared component. Releasing it is idempotent: the first call drops the hold, and every later call — including the one the consumer link makes when the consumer unloads — does nothing.
SharedComponentPoolComponentAcquireOptions Options of SharedComponentPoolComponent.acquire.
SharedComponentPoolComponentConstructorParams Parameters of SharedComponentPoolComponent.