detachCancellable method

  1. @mustCallSuper
void detachCancellable(
  1. Cancellable cancellable
)

Detaches a Cancellable from this token.

This should be called when a Cancellable completes to prevent memory leaks. You should not call this inside a Cancellable's onCancel method, as attached Cancellables are detached automatically when a token is cancelled.

Implementation

@mustCallSuper
void detachCancellable(Cancellable cancellable) {
  // Prevent modifications to the list whilst it's being iterated on by
  // ignoring detach calls if the token's been cancelled
  if (!isCancelled) _attachedCancellables.remove(cancellable);
}