performAction<T> method
Future<void>
performAction<T>(
- T desiredState,
- Function getState,
- Function action, {
- GetDeviceDetailsMethod getDetails = sdk.DevicesRepository.getDeviceDetails,
Implementation
Future<void> performAction<T>(
T desiredState, Function getState, Function action,
{GetDeviceDetailsMethod getDetails =
sdk.DevicesRepository.getDeviceDetails}) async {
if (!isPerformingAction) {
setState = WidgetState.performingAction;
try {
await action();
int numRetries = 0;
T state = getState();
while (state != desiredState && numRetries < MAX_RETRIES) {
_deviceDetail = await getDetails(_request, _deviceId);
state = getState();
await Future.delayed(Duration(milliseconds: RETRY_DELAY_MS));
numRetries++;
}
setState = WidgetState.idle;
} catch (error) {
setErrorState(error.toString());
await Future.delayed(Duration(seconds: 1))
.then((_) => setState = WidgetState.idle);
}
}
}