Javascript 如何在不使用异步/等待的情况下重写
我寻找类似的问题,将其重写为promise,而不使用async/await,但无法实现。好心帮忙Javascript 如何在不使用异步/等待的情况下重写,javascript,node.js,sendgrid-api-v3,Javascript,Node.js,Sendgrid Api V3,我寻找类似的问题,将其重写为promise,而不使用async/await,但无法实现。好心帮忙 class Mailer extends helper.Mail { ...//some methods async send() { const request = this.sgApi.emptyRequest({ method: "POST", path: '/v3/mail/send', bod
class Mailer extends helper.Mail {
...//some methods
async send() {
const request = this.sgApi.emptyRequest({
method: "POST",
path: '/v3/mail/send',
body: this.toJSON()
})
const response = await this.sgApi.API(request)
return response }}
send()
将返回一个承诺,顺便说一句。“我正在寻找其他解决方案将其转换为承诺”。您还尝试过哪些其他解决方案?把什么变成承诺?你的术语让我觉得你有点困惑async/await
仅对承诺执行任何有用的操作,因此如果您的await
语句正在执行任何有用的操作,那么this.sgApi.API(request)
必须已经返回承诺。所以,也许你想问的是“如果没有异步/等待,我如何重写这个”?承诺是以任何一种方式使用的,您不会将任何内容转换为承诺。@rveerd,我的意思是我在StackOverflow上搜索了类似的问题,并尝试了,但出现了一些错误。@jfriend00实际上我是想在不使用async/Await的情况下重写它,请编辑你的问题和标题,用合适的术语准确描述你想要的。我不知道这么简单,无论如何谢谢你的回答
class Mailer extends helper.Mail {
...//some methods
send() {
const request = this.sgApi.emptyRequest({
method: "POST",
path: '/v3/mail/send',
body: this.toJSON()
})
return this.sgApi.API(request) }}