title: Implementing async return Types on .NET Standard
body: <p>Hello guys i am trying to create my own <code>Task</code>-Like types using the <code>AsyncMethodBuilderAttribute</code> for the .NetCore framework.<br>
  So far in .<code>Net Core</code> my custom <code>Type</code> works and it can be <code>awaited</code> and i can return it as <code>async [MyTypeName]&lt;T&gt; MyMethod()</code> instead of <code>Task</code> .<br>
  However in <code>.NetStandard 2.0</code> the attribute is not present and and i tried to implement it:<br>I decorated my awaitable type with the attribute but it still does not let me use it: <code>"The return type of an async method must be void,Task,Task&lt;T&gt;"</code></p>
  
  <p>So far i can use something like this in .<code>Net Core</code> and it works !!</p>
  
  <pre><code>public async Task WrapperMethod(){
     int result=await GetIntAsync();
  }
  public async Errand&lt;int&gt; GetIntAsync()
  {
    await Task.Delay(1000);
    return 3;
  }
  </code></pre>
  
  <p><strong>Attribute</strong>:</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
      public sealed class AsyncMethodBuilderAttribute : Attribute {
          //
          // Parameters:
          //   builderType:
          public AsyncMethodBuilderAttribute(Type builderType) {
              this.BuilderType = builderType;
          }
  
          //
          public Type BuilderType { get; }
      }
  </code></pre>
  
  <p><Br>Below are the implementation of the custom type and the <code>async method builder</code>.The <code>awaiter</code> is not important in this case but i can provide the source if needed.<br><br>
   <strong>My <code>Task</code>-Like Type</strong></p>
  
  <pre><code>[AsyncMethodBuilder(typeof(Builder))]
      public partial class Errand {
  
          private readonly Builder mbuilder;
          public Errand() {
          }
          internal Errand(Builder methodBuilder) =&gt; this.mbuilder = methodBuilder;
  
          private readonly HashSet&lt;Awaiter&gt; awaiters = new HashSet&lt;Awaiter&gt;();
  
          protected bool isCompleted = false;
  
          public Awaiter GetAwaiter() {
  
              Awaiter result = new Awaiter(this);
              this.awaiters.Add(result);
              return result;
          }
  
      }
  </code></pre>
  
  <p>The custom <code>AsyncMethodBuilder</code> implementation:</p>
  
  <pre><code>public partial class Builder {
  
              #region " Compiler integration "
  
              public static Builder Create() {
                  return new Builder();
              }
  
              protected IAsyncStateMachine myStateMachine;
  
              public void Start&lt;TStateMachine&gt;(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine {
                  this.myStateMachine = stateMachine;
                  this.errand = new Errand(this);
                  stateMachine.MoveNext();
              }
  
  
              public void SetException(Exception ex) {
  
              }
  
              public void AwaitOnCompleted&lt;TAwaiter, TStateMachine&gt;(ref TAwaiter awaiter, ref TStateMachine machine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine {
  
                  var foo = machine as IAsyncStateMachine;
                  awaiter.OnCompleted(() =&gt; { foo.MoveNext(); });
              }
              public void AwaitUnsafeOnCompleted&lt;TAwaiter, TStateMachine&gt;(ref TAwaiter awaiter, ref TStateMachine machine)where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine {
  
                  IAsyncStateMachine asyncMachine = machine as IAsyncStateMachine;
                  awaiter.OnCompleted(() =&gt; asyncMachine.MoveNext());
  
              }
  
              private Errand errand;
              public Errand Task { get { return this.errand; } }
  
  
              public void SetStateMachine(IAsyncStateMachine stateMachine) {
  
              }
              public void SetResult() {
  
              }
  
              #endregion
  
  
              //  internal void AddAwaiter(Awaiter awaiter) =&gt; this.awaiters.Add(awaiter);
  
          }
  </code></pre>
  
  <p>What else should i add for it to work in .Net Standard?</p>