Browse Source

Fix taskresult and snackbar

pull/18/head
Ionite 1 year ago
parent
commit
9914498ab5
No known key found for this signature in database
  1. 23
      StabilityMatrix/Helper/SnackbarService.cs
  2. 4
      StabilityMatrix/Models/TaskResult.cs

23
StabilityMatrix/Helper/SnackbarService.cs

@ -48,20 +48,12 @@ public class SnackbarService : ISnackbarService
{
try
{
task.wa
await task;
return new TaskResult<T>
{
Result = await task
};
return new TaskResult<T>(await task);
}
catch (Exception e)
{
ShowSnackbarAsync(title, message ?? e.Message, appearance, icon, timeout).SafeFireAndForget();
return new TaskResult<T>
{
Exception = e
};
return TaskResult<T>.FromException(e);
}
}
@ -77,19 +69,12 @@ public class SnackbarService : ISnackbarService
try
{
await task;
return new TaskResult<bool>
{
Result = true
};
return new TaskResult<bool>(true);
}
catch (Exception e)
{
ShowSnackbarAsync(title, message ?? e.Message, appearance, icon, timeout).SafeFireAndForget();
return new TaskResult<bool>
{
Result = false,
Exception = e
};
return new TaskResult<bool>(false, e);
}
}
}

4
StabilityMatrix/Models/TaskResult.cs

@ -6,7 +6,7 @@ namespace StabilityMatrix.Models;
public readonly record struct TaskResult<T>
{
public readonly T? Result;
public readonly Exception? Exception = null;
public readonly Exception? Exception;
[MemberNotNullWhen(true, nameof(Result))]
public bool IsSuccessful => Exception is null && Result != null;
@ -17,7 +17,7 @@ public readonly record struct TaskResult<T>
Exception = exception;
}
public TaskResult(T? result)
public TaskResult(T result)
{
Result = result;
}

Loading…
Cancel
Save