Suppress warning CS1998: This async method lacks 'await'

前端 未结 14 976
遇见更好的自我
遇见更好的自我 2020-11-28 04:21

I\'ve got an interface with some async functions. Some of the classes that implements the interface does not have anything to await, and some might just throw. It\'s a b

14条回答
  •  -上瘾入骨i
    2020-11-28 05:18

    In case you already link against Reactive Extension, you can also do:

    public async Task NotImplemented()
    {
        await Observable.Throw(new NotImplementedException(), null as object).ToTask();
    }
    
    public async Task SimpleResult()
    {
        await Observable.Return(myvalue).ToTask();
    }
    
    
    

    Reactive and async/await are both amazing in and by themselves, but they also play well together.

    Includes needed are:

    using System.Reactive.Linq;
    using System.Reactive.Threading.Tasks;
    

    提交回复
    热议问题