javascript 中是否有用于包含同一类的同步和异步方法的调用链的简短语法?

问题描述 投票:0回答:1

我知道有2种不太方便而且看起来不优雅的方式:

  1. 通过然后:

    (new TestClass).syncMethod().asyncMethod().then(self => self.anotherSyncMethod())

  2. 通过等待:

    (await (new TestClass).syncMethod().asyncMethod()).anotherSyncMethod()

我希望它是这样的(伪代码):

(new TestClass).syncMethod().asyncMethod()->anotherSyncMethod()

其中
->
是从异步方法到同步方法的转换。

JS里有类似的东西吗?如果没有的话,以后有没有计划?

javascript async-await method-chaining
1个回答
0
投票

没有。

但是,提议的管道运营商将来可能会实现这一点。您可以在讨论中找到一些自行车棚问题,例如问题 #53#86#145#189

© www.soinside.com 2019 - 2024. All rights reserved.