Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在不使用异步/等待的情况下重写_Javascript_Node.js_Sendgrid Api V3 - Fatal编程技术网

Javascript 如何在不使用异步/等待的情况下重写

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

我寻找类似的问题,将其重写为promise,而不使用async/await,但无法实现。好心帮忙

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) }}