TimeoutCancellationToken constructor

TimeoutCancellationToken(
  1. Duration duration, {
  2. Exception? timeoutException,
  3. bool lazyStart = false,
})

Creates a TimeoutCancellationToken with the given timeout duration.

By default a TimeoutException will be used when the timeout ends. To throw a custom exception, set the timeoutException param.

If lazyStart is true, the timer will only start when it's used.

Implementation

TimeoutCancellationToken(
  Duration duration, {
  Exception? timeoutException,
  bool lazyStart = false,
}) {
  _duration = duration;
  _timeoutException = timeoutException;
  if (!lazyStart) _timer = Timer(duration, _onTimerEnd);
}