界面任务是同步的,但我需要它 return 异步

Interface task is synchronous, but I need it to return async

我已经下载了 ShopifySharp 项目并尝试通过实施 IRequestExecutionPolicy (https://github.com/nozzlegear/ShopifySharp/blob/master/ShopifySharp/Infrastructure/Policies/RetryExecutionPolicy.cs) 来制定我自己的执行策略。

在示例项目中没有这样的“未实现错误”。但是,类似的实现将此“[AsyncStateMachine(typeof(SmartRetryExecutionPolicy.d__5<>))]”放在方法之前。

据我所知,使方法异步会更改签名,因此不会实现 运行 方法。我在这方面不是很有经验,所以感谢任何帮助。

public delegate Task<RequestResult<T>> ExecuteRequestAsync<T>(CloneableRequestMessage request);

public interface IRequestExecutionPolicy
{
    Task<RequestResult<T>> Run<T>(CloneableRequestMessage requestMessage, ExecuteRequestAsync<T> executeRequestAsync, CancellationToken cancellationToken, int? graphqlQueryCost = null);
}
public class LeakyBucketExecutionPolicy : IRequestExecutionPolicy{
    public LeakyBucketExecutionPolicy(){}

    public async Task<RequestResult<T>> Run<T>(CloneableRequestMessage baseRequest, ExecuteRequestAsync<T> executeRequestAsync, CancellationToken cancellationToken, int? graphqlQueryCost = null)
    {
        //retry code
    }

From what I can tell, making the method async changes the signature

不,不是。这正是您永远不会在界面中看到 async 的原因。

async 关键字只是为了让您可以执行 awaits 和 return T 而不是 return Task<T>。编译器会为你包装它。但是签名和运行时调用方法的方式都是一样的。