run method

Future<void> run(
  1. AsyncStateTask task, {
  2. Duration? stateDelay,
  3. bool resetToInit = true,
})

Ejecuta una tarea que devuelve el StateId final.

Implementation

Future<void> run(
  AsyncStateTask task, {
  Duration? stateDelay,
  bool resetToInit = true,
}) async {
  loading();
  StateId result = 'init';
  try {
    result = await task();
    changeState(result);
  } catch (_) {
    if (contains('error')) {
      result = 'error';
      changeState('error');
    } else {
      init();
      rethrow;
    }
  }
  await Future.delayed(stateDelay ?? autoResetDelay);
  if (resetToInit) init();
}