run method
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();
}