在对组件进行单元测试时,我需要验证组件如何对在不同时间完成的任务使用react。
如何创建 Task<>
我可以随意解决?
最佳答案
您可以使用 TaskCompletionSource
创建一个完全“手动”的任务。
Represents the producer side of a Task unbound to a delegate, providing access to the consumer side through the Task property.
将完成源的Task
属性交给消费者,并(随意)调用SetResult
来完成任务。请注意,您还有 SetCanceled
和 SetException
分别表示取消和失败。
关于c# - 如何创建任务<>我可以手动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27891253/