onCancel method

void onCancel(
  1. void callback()
)

Registers a callback to be called when all listeners are paused/removed.

This is useful for pausing expensive operations like streams or timers.

Implementation

@pragma('vm:prefer-inline')
void onCancel(void Function() callback) {
  _assertNotDisposed();
  _onCancelCallbacks.add(callback);
}