来源:https://lewissbaker.github.io/2017/11/17/understanding-operator-co-await
What does the Coroutines TS give us?
The facilities the C++ Coroutines TS provides in the language can be thought of as a low-level assembly-language for coroutines. These facilities can be difficult to use directly in a safe way and are mainly intended to be used by library-writers to build higher-level abstractions that application developers can work with safely.
C ++ Coroutines TS 提供的功能可以被认为是协程的一种低级汇编语言。这些功能可能很难以安全的方式直接使用,并且主要旨在供库编写人员用来构建更高级的抽象,以便应用程序开发人员可以安全地使用它们。
Compiler <-> Library interaction
Instead, it specifies a general mechanism for library code to customise the behaviour of the coroutine by implementing types that conform to a specific interface. The compiler then generates code that calls methods on instances of types provided by the library.
它为库代码指定了一种通用机制,可通过 实现符合特定接口的类型 来自定义协程的行为。然后编译器调用 这些类型的方法 = 库提供的类型的实例的方法。
There are two kinds of interfaces that are defined by the coroutines TS: The Promise interface and the Awaitable interface.