Tag: 重构

ChatGPT 使用 Promise.All 重构/重写代码(并行发送请求)

在我的一个项目中, 我有以下代码(Node/Javascript), 它(顺序)调用了一些 API. 这些 HTTPS 请求其实是可以并行完成的, 因为它们相互独立. 然后结果会被聚合到一个数组中. 我知道可以用Promise.all来把这些请求并行化, 我就问了ChatGPT怎么弄, 看看它是否能理解并给出正确的代码: 我先用英文问 ChatGPT-3.5: Rewrite the following Python code using the Promise.all to parallelize the requests: let result = …