最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Axios请求在Promise.all之前触发

IT培训 admin 2浏览 0评论

Axios请求在Promise.all之前触发

因此我的问题指出,Axios请求在Promise.all之前发布一些信息

所以这是代码

newMessages = newMessages.map(message =>
        axios.post(URL, message, {
            auth: { username, password },
        })
    );
    // Axios requests finishes before I call Promise.all, and if I call Promise.all the requests sends second time
    await Promise.all(newMessages);

我已经尝试了其他一些变体,但所有的变体都相同

let sendMessages = [];

    for (let i = 0; i < newMessages.length; i++) {
        sendMessages.push(
            axios.post(
                URL,
                newMessages[i],
                {
                    auth: { username, password },
                }
            )
        );
    }


    // Axios requests finishes before I call Promise.all, and if I call Promise.all the requests sends second time
    await Promise.all(sendMessages);
回答如下:newMessages = newMessages.map(message => axios.post(URL, message, { auth: { username, password }, }).then(res => res) ); await Promise.all(newMessages);

Axios请求在Promise.all之前触发

因此我的问题指出,Axios请求在Promise.all之前发布一些信息

所以这是代码

newMessages = newMessages.map(message =>
        axios.post(URL, message, {
            auth: { username, password },
        })
    );
    // Axios requests finishes before I call Promise.all, and if I call Promise.all the requests sends second time
    await Promise.all(newMessages);

我已经尝试了其他一些变体,但所有的变体都相同

let sendMessages = [];

    for (let i = 0; i < newMessages.length; i++) {
        sendMessages.push(
            axios.post(
                URL,
                newMessages[i],
                {
                    auth: { username, password },
                }
            )
        );
    }


    // Axios requests finishes before I call Promise.all, and if I call Promise.all the requests sends second time
    await Promise.all(sendMessages);
回答如下:newMessages = newMessages.map(message => axios.post(URL, message, { auth: { username, password }, }).then(res => res) ); await Promise.all(newMessages);

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论