AutoReleaseBus:
Filter:
ddwPlug/Classes (extension) | Server > Abstractions

AutoReleaseBus
ExtensionExtension

A bus that frees itself only when associated objects have been freed

Description

In many cases, a Bus may need to be maintained as long as multiple objects are using it. AutoReleaseBus maintains an IdentitySet of "clients." When another object is using this bus, it should add itself as a client. When it no longer needs the bus, it should remove itself. When all clients are removed, the bus will free itself.

If the AutoReleaseBus is added as a dependent (addDependant), then the client object can broadcast theObject.changed(\didFree) and the AutoReleaseBus will remove the client.

Class Methods

Use Bus: *audio and Bus: *control to create instances.

Instance Methods

.addClient

Add a client object.

Arguments:

client

Some object using the bus.

.removeClient

Remove the client object, and automatically free the bus if all clients have been removed.

Arguments:

client

Some object using the bus.

.free

Forced "free," disregarding existing clients.

Arguments:

... why

An optional annotation, to be broadcast to any dependents.

Examples