What is the ValueTask equivalent of Task.CompletedTask?

后端 未结 1 1982
终归单人心
终归单人心 2021-01-17 17:00

I am implementing IAsyncDisposable which requires me to return a ValueTask, but sometimes my dispose method has nothing to do. How should I return

相关标签:
1条回答
  • 2021-01-17 17:58

    All structs have a default constructor. The default constructor of ValueTask creates a completed ValueTask:

    var completedValueTask = new ValueTask();
    

    Or alternatively:

    ValueTask completedValueTask = default;
    
    0 讨论(0)
提交回复
热议问题