call method

FutureOr<void> call({
  1. FutureOr<void> onStart()?,
  2. FutureOr<void> onWaited()?,
  3. FutureOr<void> onCall()?,
})

Calls the onCall function and then waits for delay before calling the onWaited function.

Implementation

FutureOr<void> call({
  FutureOr<void> Function()? onStart,
  FutureOr<void> Function()? onWaited,
  FutureOr<void> Function()? onCall,
}) {
  cancel();
  if (!_hasStarted) {
    if (_onStart != null) {
      _sequencer.then(_convertHandler(_onStart)).end();
    }
    if (onStart != null) {
      _sequencer.then(_convertHandler(onStart)).end();
    }
    _hasStarted = true;
  }
  if (_onCall != null) {
    _sequencer.then(_convertHandler(_onCall)).end();
  }
  if (onCall != null) {
    _sequencer.then(_convertHandler(onCall)).end();
  }
  _timer = Timer(delay, () {
    if (_onWaited != null) {
      _sequencer.then(_convertHandler(_onWaited)).end();
    }
    if (onWaited != null) {
      _sequencer.then(_convertHandler(onWaited)).end();
    }
    _hasStarted = false;
  });

  return _sequencer.completion.value;
}