using System;
using System.Threading.Tasks;

using CommonHelpers;

namespace MyFlat {

//**************************************************************************************************
partial class XControllerBase {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="InvalidOperationException" />
[HAsyncStatic]
protected static async Task<Exception?> Attempt_A(Func<Task> bodyA)
{
   VerifyActive();
   try { await bodyA().ConfigureAwait(false);
      return null; }
   catch (Exception e) {
      ReportException( e );
      return e; }
}

/// <exception cref="InvalidOperationException" />
[HAsyncStatic][HOptionalResult]
protected static async Task<(T? Result,Exception? Error)> Attempt_A<T>(Func<Task<T>> bodyA)
where T: class
{
   VerifyActive();
   try { return ( await bodyA().ConfigureAwait(false), null ); }
   catch (Exception e) {
      ReportException( e );
      return ( default, e ); }
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // XControllerBase
//**************************************************************************************************

} // MyFlat
