如何实现计谋没有异步CTP计谋、如何实现、CTP

2023-09-03 02:05:47 作者:采桑子

你将如何实现的东西的工作方式类似于异步CTP 等待关键字?有一个简单的实现,就像等待在所有情况下,或确实等待需要不同的实现不同场景?

How would you implement something that works similarly to the Async CTP await keyword? Is there a simple implementation that works like await in all cases, or does await require different implementations for different scenarios?

推荐答案

计谋总是涉及同一种转变 - 但它是一个pretty的痛苦之一。在库的侧等待是不是太复杂,但棘手的一​​点是,编译器生成一个状态机的你,让延续跳回到正确的地方。

await always involves the same kind of transformation - but it's a pretty painful one. The library side of await isn't too complicated, but the tricky bit is that the compiler builds a state machine for you, allowing the continuation to jump back to the right place.

这是的可能的,我的一些哈克使用iterator块(收益率的回报),你可以类似的假的东西......但是这将是pretty的难看。

It's possible that my some hacky use of iterator blocks (yield return) you could fake something similar... but it would be pretty ugly.

我给了一个 DevEx preSS研讨会一几个星期前, - 这显示了反编译code从几个例子,以及解释如何编译器生成一个任务回来,什么是awaiter必须做。这可能是对你有用。

I gave a DevExpress webinar on what the compiler is doing behind the scenes a few weeks ago - that shows decompiled code from a couple of examples, as well as explaining how the compiler builds a task to return, and what the "awaiter" has to do. It may be useful to you.