lockRelease method
The lockRelease method will call the function provided in perform
and then block the function from being called again until it has finished.
E.g. lockRelease('update', perform: () async { await handleSomething(); });
Use isLocked to check if the function is still locked. E.g. isLocked('update') // true/false
Implementation
Future<void> lockRelease(
String name, {
required Function perform,
bool shouldSetState = true,
}) async {
if (isLocked(name) == true) {
return;
}
_updateLockState(shouldSetState: shouldSetState, name: name, value: true);
try {
await perform();
} on Exception catch (e) {
NyLogger.error(e.toString());
}
_updateLockState(shouldSetState: shouldSetState, name: name, value: false);
}