addCancelCallback method

  1. @protected
void Function() addCancelCallback(
  1. void callback()
)

Registers callback past the public onCancel: the race inside abandonable needs a raw one, unguarded and removable.

Returns a remover. Unguarded means callback must not throw. It runs inside the call that cancels the job, and an error escapes from that call — Job.cancel, the cascade from a parent — and stops the pass: the callbacks registered after it never run, and Job.whenCancelled listeners hear the cancellation only when the job finishes, not when it is accepted. Register through onCancel for code that may throw.

Implementation

@protected
void Function() addCancelCallback(void Function() callback) =>
    _owner._onCancel.add(callback);