add method
Adds a subscription to this composite.
Adding to a composite that has already been cancelled is a mistake in the caller and says so — with an assertion, the way cancel does and for the same reason. Raising outright, as this used to, left behind exactly what the composite exists to prevent: the subscription was made on the line before, the throw was what kept it from ever being handed over, and nothing else held it. So it is cancelled first and complained about after: whichever build this is, the listenable is let go of.
Implementation
void add(ListenableSubscription subscription) {
if (_isDisposed) {
subscription.cancel();
// `cancel`, not `add`: the message says which call left the object
// unusable, and that is the one that ended it -- `add` is the call being
// refused. The two neighbouring assertions pass the same name.
assert(debugAssertNotDisposed(this, _isDisposed, 'cancel'));
return;
}
_subscriptions.add(subscription);
}