请与承诺连续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)
- 暂无评论