将新的承诺转换为模态方法的异步/等待
我试图将这些代码转换为异步/等待。但是看来这是不可能的!!!有人有任何建议吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我试图将这些代码转换为异步/等待。但是看来这是不可能的!!!有人有任何建议吗?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
正如评论中已经提到的那样,您无法等待在没有创造新承诺的情况下无法提供承诺接口的事件。但是,您可以在Promise Executor函数之外承诺触发事件和过程
popupdata.data
。等待
操作员仍需要在 async函数或JavaScript模块Vanilla JS中的示例:
在示例中,
this.notificationpopupsubscription
是在执行程序中同步设置的,但是在等待已解决的承诺后,弹出变量是设置的。当然,仍然需要使用适当的值来调用封闭功能/类方法。As already mentioned in comment, you can't await events that don't supply a promise interface without creating a new promise. You could, however, promisify firing of the event and process
popupData.data
outside of the promise executor function. Theawait
operator will still need to be used in an async function or JavaScript moduleExample in vanilla JS:
In the example,
this.notificationPopupSubscription
is set synchronously in the executor, but the popup variable is set after waiting for the promise to be resolved. The enclosing function/class method still needs to be called with an appropriatethis
value of course.