c# - Unity3D 中的 Awaiter 实现有什么问题?
问题描述
所以我试图制作一个简单的等待结构,允许我返回一个布尔值:
// 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;
}
}
我像这样使用它:
private async BoolResult LoadAssets (string label) {
//
// some await asyncFunction here
//
// then at the end
return new BoolResult { Value = true };
}
但我仍然得到这个编译错误:
error CS1983: The return type of an async method must be void, Task or Task<T>
我以为我BoolResult
的已经是 Task-like 了?这里有什么问题?
解决方案
推荐阅读
- discord.py - How to make my discord.py rewrite bot respond to other bots but not to webhooks?
- r - 如何使用向量中存在的字符链创建变量
- r - Logistic Regression glm() in R not recognizing numerical values
- javascript - add id prefix to css rule generated from Emotion 11
- python - 如何将 {} 显示为 python f 字符串的一部分
- excel - Using VBA to find a string in a specific column
- php - 如何使用 TLS1.0 或 TLS 1.1 卷曲网站,而我的共享主机不再支持?
- r - 如何隐藏列表中数据框的列类型?
- python - 使用“包含(文本)”在使用 Python 的 selenium 中查找父级和跟随兄弟级?
- laravel - 在单元测试中与大型数据提供者作战