withPrivilegesAsync method

Future<void> withPrivilegesAsync(
  1. RunPrivilegedAsync action, {
  2. bool allowUnprivileged = false,
})

identical to withPrivileges except action is async.

Implementation

Future<void> withPrivilegesAsync(RunPrivilegedAsync action,
    {bool allowUnprivileged = false}) async {
  if (!allowUnprivileged && !Shell.current.isPrivilegedUser) {
    throw ShellException(
      'You can only use withPrivileges when running as a privileged user.',
    );
  }
  await action();
}