So I was trying to make a simple awaitable struct that allow my to return a bool: Code (CSharp): // define a special container for returning results public struct BoolResult { public bool Value; public BoolAwaiter GetAwaiter () { return new BoolAwaiter(Value); } } // make the interface task-like public readonly struct BoolAwaiter : INotifyCompletion { private readonly bool _Input; // wrap the async operation public BoolAwaiter (bool value) { _Input = value; } // is task already done (yes) public bool IsCompleted { get { return true; } } // wait until task is done (never called) public void OnCompleted (Action continuation) => continuation?.Invoke(); // return the result public bool GetResult () { return _Input; } } And I was using it like: Code (CSharp): private async BoolResult LoadAssets (string label) { ... return new BoolResult { Value = true }; } I don't get why C# tells me: Didn't my BoolResult already meet the "Task-like" requirement?
So people told me I need to declare AsyncMethodBuilder, because Task-like only makes it await-able. But to return this thing in an async function, is a different matter. https://github.com/dotnet/roslyn/blob/master/docs/features/task-types.md Problem is, I need AsyncMethodBuilder attribute, and I don't think it's available in Unity 2018.3? With Code (CSharp): using System.Runtime.CompilerServices; AsyncMethodBuilder is still not found... (I think Unity 2018.3 has C# 7 support, but perhaps it was introduced at later version?)
I am now starting to understand why all those Async library for Unity ships their own CompileServices.dll...