activeAsync<T> method
Use this function when you have a long running task asynchronously. it handles setting actively status from true to false once done.
isRunningKey
is a String value rep Activity running status, this value
could be used to find the active ActiveController.
Example:
Future<void> loadTasks() async {
final tasks = await activeAsync<Tasks>(
() async => await taskService.getAllActiveTasks(),
isRunningKey: 'loadTasks'
);
}
Implementation
Future<T> activeAsync<T>(Future<T> Function() task,
{dynamic isRunningKey}) async {
setRunningStatus(isRunning: true, isRunningKey: isRunningKey);
try {
final doTask = await task();
return doTask;
} finally {
setRunningStatus(isRunning: false, isRunningKey: isRunningKey);
}
}