【问题标题】:Are the async/await keywords in python 3.5 inspired by async/await in C#? [closed]python 3.5 中的 async/await 关键字是否受到 C# 中的 async/await 的启发? [关闭]
【发布时间】:2023-03-27 01:32:03
【问题描述】:

python 3.5 中的async/await(语法和关键字)与 C# 中的async/await 非常相似。

C# 示例:

async void asyncTask(){
    await asyncMethod()
}

Python 示例:

async def asyncTask():  
    await async_method()

问题:python 3.5 中的 async/await 是否受到 C# 中的 async/await 的启发?如果是,为什么?

【问题讨论】:

    标签: c# python asynchronous python-3.5


    【解决方案1】:

    PEP 492(添加awaitasync 关键字的建议)中,C# 使用它们的是mentioned(除了其他):

    为什么要用“async”和“await”关键字

    async/await 在编程语言中并不是一个新概念:

    • 很久以前C#就有了[5];
    • 建议在 ECMAScript 7 [2] 中添加 async/await;另见 Traceur 项目 [9];
    • Facebook 的 Hack/HHVM [6];
    • Google 的 Dart 语言 [7];
    • 斯卡拉 [8];
    • 建议在 C++ [10] 中添加 async/await;
    • 和许多其他不太流行的语言。

    这是一个巨大的好处,因为一些用户已经有使用 async/await 的经验,并且因为它使在一个项目中使用多种语言变得更加容易(例如 Python 和 ECMAScript 7)。

    (强调我的)

    所以关键字名称确实受到了 C#(和其他语言)的启发,至于“为什么”,这也在最后一段中进行了解释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-04
      • 2012-11-28
      • 1970-01-01
      • 2012-10-12
      • 2016-03-16
      • 1970-01-01
      • 2015-05-04
      • 2016-12-30
      相关资源
      最近更新 更多