最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

请与承诺连续got.js请求[复制]

运维笔记admin13浏览0评论

请与承诺连续got.js请求[复制]

请与承诺连续got.js请求[复制]

这个问题已经在这里有一个答案:

  • How do I return the response from an asynchronous call? 37个回答
回答如下:

你不应该让他们阻塞线程同步请求,这将是一个服务器,并同步请求灾难性已经过时了很久的客户端了。

我觉得你有一些学习做一下异步代码,但在平均时间你看看文档?第一个片段展示了它是多么微不足道使用asyc/await异步工作:

const got = require('got');

(async () => {
    try {
        const response = await got('https://sindresorhus');
        const token = response.body;
        // ... do stuff with token
        const nextResponse = await got('http://sindresorhus', {
          headers: {
            Authorization: `Bearer ${token}`,
          },
        })
    } catch (error) {
        console.error(error.response.body);
    }
})();
发布评论

评论列表(0)

  1. 暂无评论